UIImage *image = nil;
// 下面方法,第一个参数表示区域大小。第二个参数表示是否是非透明的。如果需要显示半透明效果,需要传NO,否则传YES。第三个参数就是屏幕密度了,调整清晰度。
UIGraphicsBeginImageContextWithOptions(table.contentSize, YES, [UIScreen mainScreen].scale);
//3、tableView内容
CGPoint savedContentOffset = table.contentOffset;
CGRect savedFrame = table.frame;
CGSize contentSize = table.contentSize;
CGRect oldBounds = table.layer.bounds;
if (@available(iOS 13.0, *)) {
[table.layer setBounds:CGRectMake(oldBounds.origin.x, oldBounds.origin.y,
contentSize.width, contentSize.height)];
}
CGFloat transY = 0;//navFrame.size.height;
CGContextTranslateCTM(UIGraphicsGetCurrentContext(), 0, transY);
// [colorLayer renderInContext:UIGraphicsGetCurrentContext()];
table.contentOffset = CGPointZero;
table.frame = CGRectMake(0, 0, contentSize.width, contentSize.height);
[table.layer renderInContext:UIGraphicsGetCurrentContext()];
CGContextTranslateCTM(UIGraphicsGetCurrentContext(), 0, -transY);
if (@available(iOS 13.0, *)) {
[table.layer setBounds:oldBounds];
}
//4、生成图片
image = UIGraphicsGetImageFromCurrentImageContext();
//5、恢复tableView的显示
table.contentOffset = savedContentOffset;
table.frame = savedFrame;
//6、结束绘制
UIGraphicsEndImageContext();
网友评论