Skip to content

Instantly share code, notes, and snippets.

@molon
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save molon/6523ffb8d8feaf28d493 to your computer and use it in GitHub Desktop.

Select an option

Save molon/6523ffb8d8feaf28d493 to your computer and use it in GitHub Desktop.
capture for UIScrollView
- (UIImage*)image
{
UIImage *image = nil;
UIGraphicsBeginImageContextWithOptions(self.contentSize, NO, 0.0f);
{
CGPoint origOffset = self.contentOffset;
CGRect origFrame = self.frame;
self.frame = CGRectMake(0, 0, self.contentSize.width, self.contentSize.height);
self.contentOffset = CGPointZero;
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
image = UIGraphicsGetImageFromCurrentImageContext();
self.frame = origFrame;
self.contentOffset = origOffset;
}
UIGraphicsEndImageContext();
return image;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment