iOS使用代码截图
2016-04-15 23:14 Hi,David 阅读(255) 评论(0) 编辑 收藏 举报/** * 截图代码 * * @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; }