Skip to content

Instantly share code, notes, and snippets.

@Kila2
Created August 20, 2018 07:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kila2/b4a9e0c218f4ffdd81502a8da5029d8a to your computer and use it in GitHub Desktop.
Save Kila2/b4a9e0c218f4ffdd81502a8da5029d8a to your computer and use it in GitHub Desktop.
getSnapshotFromView
+ (nullable UIImage *)getSnapshotFromView:(UIView *)view useScreenUpdate:(BOOL)useScreenUpdate
{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, [UIScreen mainScreen].scale);
UIImage * snapshotImage = NULL;
if ([view respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)] && useScreenUpdate) {
BOOL drawSuccess = [view drawViewHierarchyInRect:view.bounds afterScreenUpdates:NO];
if (drawSuccess) {
snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
}
} else {
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
}
UIGraphicsEndImageContext();
return snapshotImage;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment