Skip to content

Instantly share code, notes, and snippets.

@manolosavi
Last active April 5, 2017 15:43
Show Gist options
  • Save manolosavi/815d91a8a6ee6184410de65c51710c7a to your computer and use it in GitHub Desktop.
Save manolosavi/815d91a8a6ee6184410de65c51710c7a to your computer and use it in GitHub Desktop.
Obj-C function to get a UIImage from a UIView.
@import QuartzCore;
+ (UIImage *)imageFromView:(UIView *)view {
UIGraphicsBeginImageContextWithOptions(view.bounds.size, false, 0);
[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:true];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment