【发布时间】:2012-07-13 13:48:35
【问题描述】:
我想为我的表格视图截取所有单元格的屏幕截图,而不仅仅是可见单元格。行数是动态的。
如果有 30 行,那么我希望在一个屏幕截图中显示所有 30 行。 我尝试使用 tableview 的总高度作为
self.tblView.contentSize.height
使用此代码,我可以获取所有单元格的屏幕,但除了可见单元格之外,屏幕的所有其他部分都是空白的。
我正在使用下面的代码截屏
- (UIImage *)captureView:(UIView *)view
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
screenRect.size.height=self.tblView.contentSize.height;
UIGraphicsBeginImageContext(screenRect.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
[[UIColor blackColor] set];
CGContextFillRect(ctx, screenRect);
[view.layer renderInContext:ctx];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
感谢您的帮助。
【问题讨论】:
-
我认为这比只截屏更复杂,因为细胞没有被淹没。
-
@Alex Terente,有没有其他方法可以捕获所有单元格?
-
您可以在 CGContext 中绘制所有内容并从该上下文中获取图像。
标签: iphone