Skip to content

Instantly share code, notes, and snippets.

@fantattitude
Created December 21, 2012 15:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fantattitude/4353648 to your computer and use it in GitHub Desktop.
Save fantattitude/4353648 to your computer and use it in GitHub Desktop.
UIView to UIImage category method by @Dimillian
+ (UIImage*)captureView:(UIView *)viewToCapture {
if([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
UIGraphicsBeginImageContextWithOptions(viewToCapture.bounds.size, NO, [UIScreen mainScreen].scale);
else
UIGraphicsBeginImageContext(viewToCapture.bounds.size);
[viewToCapture.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment