自己写一个对 UIImage 的类目
@implementation UIImage (XYShutScreen)
+ (instancetype) captureWithView:(UIView *)view
{
UIGraphicsBeginImageContextWithOptions(view.frame.size, NO, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
+ (void)savePictureWithImage:(UIImage *)image
{
UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);
}
@end
在截图的方法里面调用该方法即可:
[UIImage savePictureWithImage:[UIImage captureWithView:self.view]];
本文介绍如何在iOS应用中自定义实现对UIView的截图功能,包括捕获指定视图的图像并保存到相册。

被折叠的 条评论
为什么被折叠?



