Skip to content

Instantly share code, notes, and snippets.

@madson
Created December 7, 2011 00:48
Show Gist options
  • Save madson/1440850 to your computer and use it in GitHub Desktop.
Save madson/1440850 to your computer and use it in GitHub Desktop.
Getting UIImage from UIView
- (UIImage *)captureView:(UIView *)view {
CGRect rect = [view bounds];
UIGraphicsBeginImageContext(rect.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
[[UIColor blackColor] set];
CGContextFillRect(ctx, rect);
[view.layer renderInContext:ctx];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment