Skip to content

Instantly share code, notes, and snippets.

@cybersamx
Created August 6, 2014 17:39
Show Gist options
  • Save cybersamx/430c33b19d49487d1d4c to your computer and use it in GitHub Desktop.
Save cybersamx/430c33b19d49487d1d4c to your computer and use it in GitHub Desktop.
Create a UIImageView representing a visual snapshot of another UIView object.
- (UIImageView *)createSnapshotFromView:(UIView *view) {
UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, 0.0f);
CGContextRef context = UIGraphicsGetCurrentContext();
[view.layer renderInContext:context];
UIImage *snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return [[UIImageView alloc] initWithImage:snapshotImage];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment