//view:需要截取的视图
//rect:截取的范围
- (UIImage *)imageFromView: (UIView *)view atFrame:(CGRect)rect{
UIGraphicsBeginImageContext(view.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
UIRectClip(rect);
[view.layer renderInContext:context];
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
}
网友评论