iOS UIView生成图片

有的时候需要将当前视图生成一张图片,例如在做分享的时候,直接分享当前视图为一张图片。

具体代码如下:

UIGraphicsBeginImageContextWithOptions(self.view.size, NO, [UIScreen mainScreen].scale);

[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

原文地址:https://www.cnblogs.com/king-peng/p/9036117.html