Skip to content

Instantly share code, notes, and snippets.

@wooster
Last active August 29, 2015 13:57
Show Gist options
  • Save wooster/9480310 to your computer and use it in GitHub Desktop.
Save wooster/9480310 to your computer and use it in GitHub Desktop.
- (IBAction)snapshot:(id)sender {
UIButton *button = sender;
UIView *v = button.superview;
CGRect allTheViews = CGRectUnion(v.bounds, button.frame);
UIGraphicsBeginImageContext(allTheViews.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, -allTheViews.origin.x, -allTheViews.origin.y);
[v.layer renderInContext:context];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[UIImagePNGRepresentation(img) writeToFile:@"/tmp/foo.png" atomically:NO];
}
@jscalo
Copy link

jscalo commented Mar 11, 2014

Boom.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment