自己写一个对 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]];