来自UIView的图片

And*_*ang 16 objective-c uiview

有没有可能从UIView创建一个图像?

谢谢,安德烈亚斯

els*_*ooo 47

#import "QuartzCore/QuartzCore.h"将框架添加到项目后.然后做:

UIGraphicsBeginImageContext(yourView.frame.size);
[[yourView layer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

// The result is *screenshot
Run Code Online (Sandbox Code Playgroud)