gpt4 book ai didi

iphone - 保存 textView 的图像

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:50:14 25 4
gpt4 key购买 nike

UIGraphicsBeginImageContext(theView.contentSize);
CGContextRef context = UIGraphicsGetCurrentContext();

[theView setNeedsLayout];
[theView.layer renderInContext:context];
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSLog(@"theImage %@",theImage);
return theImage;

我想保存 textView 的图像,但我无法捕捉到完整的 textView。该图像仅显示屏幕上显示的文本。我不是美国人,所以我的英语很差,我无法从我们的 TC 网站上得到答案。

最佳答案

该代码的作用实质上是获取屏幕截图,因此没有真正的方法让它显示完整的 UITextView。即使尝试以编程方式滚动 UITextView 并截取该区域的多个屏幕截图以将它们拼接在最终图像上也将是一场噩梦,因为输入长度不同,如果不切断文本就无法知道滚动多远。

我建议使用 this great answer将 UITextView 调整为您的内容大小,抓取图像,然后如果需要,将其恢复为原始高度。

关于iphone - 保存 textView 的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11435414/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com