【问题标题】:How to save a UITableView's content as a PNG file?如何将 UITableView 的内容保存为 PNG 文件?
【发布时间】:2011-08-08 12:20:12
【问题描述】:

我的应用程序在 contentview 内有一个 UITableView,并且 tableview 的 contentsize 在 contentview 之外,当我使用以下代码从 tableview 生成 PNG 文件时,只生成了可见的内容。但是我想将整个tableview生成为最终的PNG文件,怎么办?

UIGraphicsBeginImageContext(self._tableView.contentSize);
[self._tableView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

return UIImagePNGRepresentation(image);

【问题讨论】:

    标签: iphone uitableview png


    【解决方案1】:

    这似乎是不可能的,因为表格视图的内容只有在为该索引路径调用其- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 时才可用。并且仅当 tableview 单元格可见时才会调用它。由于内容不可用,您无法将其保存为 PNG。

    【讨论】: