iOS使用代码截图

/**
 *  截图代码
 *
 *  @param view 需要截图的view
 *  @param rect 需要截取的区域
 *
 *  @return 返回截取的对象
 */
+ (UIImage *)viewSnapshot:(UIView *)view withInRect:(CGRect)rect
{
    
    UIGraphicsBeginImageContext(view.bounds.size);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    CGImageRef imageRef = CGImageCreateWithImageInRect(image.CGImage,rect);
    image = [UIImage imageWithCGImage:imageRef];
    CGImageRelease(imageRef);
    return image;
}
原文地址:https://www.cnblogs.com/wobuyayi/p/5397255.html