Take a snapshot of a UIView as a UIImage
Problem
You want to take a snapshot of a UIView as a UIImage.
Solution
It's sometimes useful to create a UIImageView representing a visual snapshot of another UIView object. This new UIImageView can be useful for animation.
UIView *subView = self.viewWithManySubViews;
UIGraphicsBeginImageContextWithOptions(subView.bounds.size, YES, 0.0f);
CGContextRef context = UIGraphicsGetCurrentContext();
[subView.layer renderInContext:context];
UIImage *snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView *snapshotImageView = [[UIImageView alloc] initWithImage:snapshotImage];
Written by Samuel Chow
Related protips
1 Response
Is this solution in Swift as well?
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ios
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#