如何将 UILabel 绘制到上下文中
我正在尝试将 UIlabel 绘制到新上下文中的特定位置。我知道您可以轻松地将 NSString 绘制到上下文中,但我想保留 UILabel 的文本大小、颜色和自动换行样式。感谢您的帮助!
UIGraphicsBeginImageContext(targetSize);
// here is where I want to draw UILabel to context
UIGraphicsEndImageContext();
I'm trying to draw a UIlabel into a new Context, at a specific location. I know you can draw just the NSString into a context easily, but I want to retain the text size, color, and word wrap style of the UILabel. Thanks for your help!
UIGraphicsBeginImageContext(targetSize);
// here is where I want to draw UILabel to context
UIGraphicsEndImageContext();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
-renderInContext 绘制任何视图 :
,但如果您只需要保留文本大小、颜色和自动换行样式,您可以简单地使用-drawInRect:withFont:lineBreakMode:alignment:
自定义所有选项。还有 UILabel 中的
-drawTextInRect:
方法,但 Apple 表示“您不应该调用此方法”直接方法。”You could draw any view using
-renderInContext:
, but if all you need is just retain the text size, color and word wrap style, you could simply use-drawInRect:withFont:lineBreakMode:alignment:
to customize all options.There is also a
-drawTextInRect:
method in UILabel, but Apple says "You should not call this method directly."