用文本颜色保存Uilabel



我想用uilabeltextfields保存图像。我可以保存它们,但所有的文字场都是黑色的。我试图从属性检查器中更改,但没有任何改变。任何人都可以帮助我保存带有白色的Uilabel文本字段。我也需要大胆的字体字符。

谢谢。

UIGraphicsBeginImageContextWithOptions(self.mainImage.bounds.size, YES, 0.0);
    [self.mainImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    [self.goalkeeperImage.image drawInRect:CGRectMake(self.goalkeeperImage.frame.origin.x, self.goalkeeperImage.frame.origin.y, self.goalkeeperImage.frame.size.width, self.goalkeeperImage.frame.size.height)];
    [self.goalkeeperText.text drawInRect:CGRectMake(self.goalkeeperText.frame.origin.x, self.goalkeeperText.frame.origin.y, self.goalkeeperText.frame.size.width,self.goalkeeperText.frame.size.height) withAttributes:nil ];
    [self.datelabeltext.text drawInRect:CGRectMake(self.datelabeltext.frame.origin.x, self.datelabeltext.frame.origin.y, self.datelabeltext.frame.size.width,self.datelabeltext.frame.size.height) withAttributes: nil  ];
    UIImage *SaveImage =  UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    UIImageWriteToSavedPhotosAlbum(SaveImage, self,@selector(image:didFinishSavingWithError:contextInfo:), nil);

如果您要渲染的所有图像和标签都包含在单个视图中(并且没有其他对象),则可以使用此代码捕获包含的视图:

// Draw the high resolution image to the context
UIGraphicsBeginImageContextWithOptions(drawView.bounds.size, NO, 0.0);
[[drawView layer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage *ViewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// Save the high resolution image as a png
NSData *pngData = UIImagePNGRepresentation(ViewImage);
[pngData writeToFile:@"__Path__/image@2x.png" atomically:NO];
// Draw the low resolution image to the context
UIGraphicsBeginImageContext(drawView.bounds.size);
[[drawView layer] renderInContext:UIGraphicsGetCurrentContext()];
ViewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// Save the low resolution image as a png
pngData = UIImagePNGRepresentation(ViewImage);
[pngData writeToFile:@"__Path__/image.png" atomically:NO];

您可能不需要代码将图像保存为PNG,您可以将ViewImage用作您传递到另一个功能的UIImage。这只是我用来将视图保存为png的代码。

最新更新