Bar*_*zyk 4 uitableview ios swift
我对UITableView一些数据很简单.桌子的高度大于屏幕尺寸.现在我需要抓住这个表的截图(整个表格).我知道内容后的单元格已经出列,但也许有一种方法可以捕获它.不是吗?
试试这个:
func generateImage(tblview:UITableView) ->UIImage{
UIGraphicsBeginImageContext(tblview.contentSize);
tblview.scrollToRowAtIndexPath(NSIndexPath(forRow: 0, inSection: 0), atScrollPosition: UITableViewScrollPosition.Top, animated: false)
tblview.layer.renderInContext(UIGraphicsGetCurrentContext())
let row = tblview.numberOfRowsInSection(0)
let numberofRowthatShowinscreen = 4
var scrollCount = row / numberofRowthatShowinscreen
for var i=0;i < scrollCount ; i++ {
tblview.scrollToRowAtIndexPath(NSIndexPath(forRow: (i+1)*numberofRowthatShowinscreen, inSection: 0), atScrollPosition: UITableViewScrollPosition.Top, animated: false)
tblview.layer.renderInContext(UIGraphicsGetCurrentContext())
}
let image:UIImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext();
return image;
}
Run Code Online (Sandbox Code Playgroud)
和之后的通话方法一样.
var imageView = UIImageView()
imageView.image =generateImage(tableView)
Run Code Online (Sandbox Code Playgroud)
要截取 UIView 的屏幕截图,您可以使用以下命令:
UIGraphicsBeginImageContext(tableview.frame.size)
tableview.layer.renderInContext(UIGraphicsGetCurrentContext())
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
Run Code Online (Sandbox Code Playgroud)
这适用于任何可见的内容,并且可能适用于任何已加载但不在屏幕上的视图。
在 UITableView 中,仅加载可见单元格以及表格每一端的 1 个屏幕外单元格。其他的实际上还不存在。所以你无法“捕获”它们。
| 归档时间: |
|
| 查看次数: |
3271 次 |
| 最近记录: |