I have a UITableView
which is populated with some data but since it contains data that is more cells than the viewable area of the screen, I only managed to get onl
I think everyone forgets that UITableView
is a UIScrollView
after all. There is no need to calculate cells, height etc. You can simply create your context with the contentSize
, set tableView.frame.size = tableView.contentSize
and render in context.
Please see this example
UIGraphicsBeginImageContext(tableView.contentSize)
let context = UIGraphicsGetCurrentContext()
let cachedOffset = CGPoint(x:tableView.contentOffset.x , y:tableView.contentOffset.y)
let cachedFrame = tableView.frame
tableView.contentOffset = .zero
tableView.frame = CGRect(x: 0, y: 0, width: tableView.contentSize.width, height: tableView.contentSize.height)
tableView.layer.render(in: context)
tableView.frame = cachedFrame
tableView.contentOffset = cachedOffset
if let image = UIGraphicsGetImageFromCurrentImageContext() {
let imageView = UIImageView(image: image)
self.createPDF(fromUIViews:myImage saveToDocumentsWithFileName:"PDF Name")
}
UIGraphicsEndImageContext()