Skip to content

Instantly share code, notes, and snippets.

@zapsleep
Created December 7, 2012 13:15
Show Gist options
  • Save zapsleep/4233212 to your computer and use it in GitHub Desktop.
Save zapsleep/4233212 to your computer and use it in GitHub Desktop.
UIKit screenshot snippet
- (UIImage*)screenshotFromView:(UIView *)view
{
CGSize imageSize = [view bounds].size;
if (NULL != UIGraphicsBeginImageContextWithOptions)
UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
else
UIGraphicsBeginImageContext(imageSize);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGContextTranslateCTM(context,
[view center].x,
[view center].y);
CGContextConcatCTM(context, [view transform]);
CGContextTranslateCTM(context,
-[view bounds].size.width * [view anchorPoint].x,
-[view bounds].size.height * [view anchorPoint].y);
[view renderInContext:context];
CGContextRestoreGState(context);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment