截图功能

//.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];

}

谢谢阅读!

你可能感兴趣的:(截图功能)