2

i'm trying to take the snapshot of the all content of a UIScrollView, i have found some code here on SO, and this code below working on a half, because the snapshot if of the all uiscrollview, but the background is black, this is the code:

UIImage* image = nil;

UIGraphicsBeginImageContextWithOptions(_scrollView.contentSize,YES,0.0f);
{
    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()];
    image = UIGraphicsGetImageFromCurrentImageContext();

    _scrollView.contentOffset = savedContentOffset;
    _scrollView.frame = savedFrame;

}
UIGraphicsEndImageContext();

how i can have also the background in the snapshot?

Piero
  • 9,173
  • 18
  • 90
  • 160

1 Answers1

0

The background isn't getting the screen shot because it is not in the scroll view, so you have a few options, if your scrollView takes up the entire view's area then you could take a screen shot of self.view instead, if it takes up a small area, then your only other option is to put the background with in the scrollView and take a screen shot of the scrollView. This would mean allocating a new UIImageView, resetting the frame to have the proper width, height, origin, and then adding it to the scroll view, take the snapshot, then remove this UIImageView

A'sa Dickens
  • 2,045
  • 1
  • 16
  • 21