Reputation: 1499
How can I turn a UIView (with subviews as UIImageViews) into a UIImage programatically?
Is this a common practice?
Upvotes: 0
Views: 198
Reputation: 7252
For anyone looking for a Swift 4 answer on iOS 10+
let renderer = UIGraphicsImageRenderer(bounds: view.bounds)
let image = renderer.image { rendererContext in
view.layer.render(in: rendererContext.cgContext)
}
Upvotes: 1
Reputation:
Seems you want a "screenshot" of a particular view?
UIGraphicsBeginImageContext(view.bounds.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
[view.layer renderInContext:ctx];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Upvotes: 7