user1518142
user1518142

Reputation: 21

Save an image of the textView

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

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

I want to save an image of the textView but I can't catch the full textView. The image only shows the text which is displayed on the screen. I am not an American so my English is so poor and I can't get the answer from our TC website.

Upvotes: 2

Views: 195

Answers (1)

andycam
andycam

Reputation: 1692

What that code does is essentially take a screenshot, so there's no real way of getting it to display the full UITextView. Even trying to scroll the UITextView programmatically and taking several screenshots of that area to stitch them together on the final image would be a nightmare, with varying input lengths there's no way of knowing how far to scroll without chopping text off.

What I'd recommend is using this great answer to resize the UITextView to your content size, grab the image, and then if you need to, restore it to its original height.

Upvotes: 1

Related Questions