//view转成Image
- (UIImage *)convertViewToImage:(UIView *)view {
UIImage *imageRet = [[UIImage alloc]init];
//开启上下文 参数1:CGSize size 尺寸, 参数2:BOOL opaque 透明度, 参数3:CGFloat scale 比例
UIGraphicsBeginImageContextWithOptions(view.frame.size, YES, [UIScreen mainScreen].scale);
//获取图像
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
imageRet = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return imageRet;
}
tableView scrollView可以滚动的控件转成图片
- (UIImage *)convertViewToImage {
UIImage *image = nil;
UIGraphicsBeginImageContextWithOptions(self.tableView.contentSize, YES, [UIScreen mainScreen].scale);
CGPoint savedContentOffset = self.tableView.contentOffset;
CGRect savedFrame = self.tableView.frame;
self.tableView.contentOffset = CGPointZero;
self.tableView.frame = CGRectMake(0, 0, self.tableView.contentSize.width, self.tableView.contentSize.height);
[self.tableView.layer renderInContext:UIGraphicsGetCurrentContext()];
image = UIGraphicsGetImageFromCurrentImageContext();
self.tableView.contentOffset = savedContentOffset;
self.tableView.frame = savedFrame;
return image;
}