将UIView变成UIImage

sta*_*lew 0 objective-c uiview uiimageview ios

如何以编程方式将UIView(带子视图为UIImageViews)转换为UIImage?

这是一种常见做法吗?

小智 7

看起来你想要一个特定视图的"截图"?

UIGraphicsBeginImageContext(view.bounds.size); 
CGContextRef ctx = UIGraphicsGetCurrentContext();
[view.layer renderInContext:ctx];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Run Code Online (Sandbox Code Playgroud)