0

I'm trying to get an image of the contents of a UITextView, including the part that is not currently visible on the screen. I do it exactly as pointed out in the first answer here: Getting a screenshot of a UIScrollView, including offscreen parts, except for using a UITextView instead of a UIScrollView. Unfortunately, no matter what changes I do to the code, I'm always only getting a part of my UITextView, which is about 1024x315 (I test it on the iPad simulator, in landscape orientation). Why is the size so weird and how can I make it as I want to?

That's how I'm saving the image (ResultsView is an instance of UITextView):

UIImage* image = nil;

UIGraphicsBeginImageContext(ResultsView.contentSize);
CGPoint savedContentOffset = ResultsView.contentOffset;
CGRect savedFrame = ResultsView.frame;

ResultsView.contentOffset = CGPointZero;
ResultsView.frame = CGRectMake(0, 0, ResultsView.contentSize.width, ResultsView.contentSize.height);

[ResultsView.layer renderInContext: UIGraphicsGetCurrentContext()];
image = UIGraphicsGetImageFromCurrentImageContext();

ResultsView.contentOffset = savedContentOffset;
ResultsView.frame = savedFrame;
UIGraphicsEndImageContext();

NSData * data = UIImagePNGRepresentation(image);
UIImageWriteToSavedPhotosAlbum([UIImage imageWithData:data], nil, nil, nil);
Community
  • 1
  • 1
Yashman
  • 111
  • 1
  • 11

0 Answers0