//.h
+ (UIImage *)screenshotFrom:(UIView *)view frame:(CGRect)frame;
//.m
+ (UIImage *)screenshotFrom:(UIView *)view frame:(CGRect)frame {
UIGraphicsBeginImageContext(view.frame.size);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGImageRef cgImage= CGImageCreateWithImageInRect([image CGImage], frame);
return [UIImage imageWithCGImage:cgImage];
}
谢谢阅读!
网友评论