2

I have a scrollview, frame size is 480x265 and content size is 1800x600.

I have a lot of UIView added as a subview to this scrollview.

May I know how should I be able to convert this scrollview to an image?

Many thanks for any comments/help in advance!

user229044
  • 232,980
  • 40
  • 330
  • 338
Erwin
  • 21
  • 3
  • This is a duplicate of http://stackoverflow.com/questions/3539717/getting-a-screenshot-of-a-uiscrollview-including-offscreen-parts – Rambatino May 19 '15 at 15:20

1 Answers1

3
- (void)submitClicked
{
     UIGraphicsBeginImageContext(scrollView.contentSize);

     CGPoint savedContentOffset = scrollView.contentOffset;
     CGRect savedFrame = scrollView.frame;

     scrollView.contentOffset = CGPointZero;
     scrollView.frame = CGRectMake(0, 0, scrollView.contentSize.width,  scrollView.contentSize.height);
     [scrollView.layer renderInContext: UIGraphicsGetCurrentContext()];     
     UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

     scrollView.contentOffset = savedContentOffset;
     scrollView.frame = savedFrame;

     UIGraphicsEndImageContext();
}  
Omar
  • 105
  • 4
Areeba Khan
  • 71
  • 1
  • 10