如何给UIScrollView截图
/** 获取scrollView的长截图*/
- (UIImage *)getLongImage:(UIScrollView *)scrollView
{
CGRect oldFrame = scrollView.layer.frame;
CGSize size = scrollView.contentSize;
UIGraphicsBeginImageContextWithOptions(size, NO, [UIScreen mainScreen].scale);
//这里需要你修改下layer的frame,不然只会截出在屏幕显示的部分
scrollView.layer.frame = CGRectMake(0, 0, size.width, size.height);
[scrollView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
scrollView.layer.frame = oldFrame;
return image;
}
网友评论