NSString drawAtPoint 与 [英] NSString drawAtPoint with
本文介绍了NSString drawAtPoint 与的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想制作一些带有标签的 UIImage,如果未加载照片,它将显示.在应用程序中生成此图像更有用,因为它很容易本地化文本.我有代码:
I want to make some UIImage with label, which will show, if photo isn't loaded. Generation of this image in application is more useful, because it very easy to localize text. I have code:
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;
但它只绘制第一行,就像截图一样.
But it draw only first line, like in screenshot.
我哪里错了?
谢谢.
推荐答案
来自 文档 -drawAtPoint:forWidth:withFont:代码>:
在当前图形上下文中的指定点使用指定的字体和属性在一行中绘制字符串.
Draws the string in a single line at the specified point in the current graphics context using the specified font and attributes.
因此,使用不同的方法.-drawInRect:withFont:lineBreakMode:
看起来是个不错的候选.
Ergo, use a different method. -drawInRect:withFont:lineBreakMode:
looks like a solid candidate.
这篇关于NSString drawAtPoint 与的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文