如何从 UITextView 中的图像上绘制由多行字符串组成的文本?
我想从 UITextView 获取多行字符串并将其绘制在图像上, 图像中文本的位置必须与 UITextView 中的位置完全相同,但我不想将 textView 添加到 UIImageView,我需要一个由这些文本组成的新图像,这可能吗?有什么建议这样做吗?
i want to get a multiple line string from a UITextView and draw it on a image,
the position of text in the image must exactly same as the position in UITextView but i dont want jus add the textView to UIImageView, i need a new image consists of those text, is it possible? any suggestion to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将任何 UIView 的内容捕获到 UIImage 中。首先,创建一个空的 UIView 并将 UIImageView 和 UITextView 定位为子视图:
现在创建一个图形上下文并将 ParentView 绘制到其中:
现在您有了一个 UIImage,其中包含 UIImageView 和 UITextField 的内容,可以通过网络显示、保存或发送。
You can capture the contents of any UIView into a UIImage. First, create an empty UIView and position your UIImageView and UITextView as subviews:
Now create a graphics context and draw parentView into it:
You now have a UIImage with the contents of your UIImageView and UITextField to display, save, or send over the network.
这是一个很好的解决方案,谢谢。
我想补充一点,您需要添加
到您的导入中,这样警告就会消失。
This was a good solution, thanks.
I would like to add that you need to add
To your imports so the warnings go away.