我想制作一些带有标签的 UIImage,如果未加载照片,它将显示。在应用程序中生成此图像更有用,因为它很容易本地化文本。我有代码:
NSString *text = @"Photo not loaded yet. Please wait.";
UIFont *font = [UIFont boldSystemFontOfSize:35];
CGSize imageSize = CGSizeMake(400, 400);
CGSize constraint = CGSizeMake(imageSize.width * 0.8f, imageSize.height * 0.8f);
CGSize textSize = [text sizeWithFont:font constrainedToSize:constraint lineBreakMode:NSLineBreakByWordWrapping];
UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0.0);
CGPoint pointToDraw = CGPointMake((imageSize.width - textSize.width) / 2, (imageSize.height - textSize.height) / 2);
[text drawAtPoint:pointToDraw forWidth:textSize.width withFont:font lineBreakMode:NSLineBreakByWordWrapping];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
但它只绘制第一行,就像在屏幕截图中一样。
我哪里错了?
谢谢你。