I have simple UITableView
with some data. The table\'s height is greater than the screen size. Now I need to catch screenshot of this table (a whole table). I k
Swift 3 version of Young Hoo Kim's answer works for me:
func generateTableViewImage(_ tableView: UITableView) -> UIImage? {
UIGraphicsBeginImageContextWithOptions(tableView.contentSize, false, UIScreen.main.scale)
for section in 0..<tableView.numberOfSections {
for row in 0..<tableView.numberOfRows(inSection: section) {
let indexPath = IndexPath(row: row, section: section)
guard let cell = tableView.cellForRow(at: indexPath) else { continue }
cell.contentView.drawHierarchy(in: cell.frame, afterScreenUpdates: true)
}
}
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
It should be noted that if your UITableView is particularly long you may not be able to capture it with the function above as it may require too large an image.