Try this:
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 numberofRowsThatShowOnScreen = 4
var scrollCount = row / numberofRowthatShowinscreen
for var i = 0; i < scrollCount; i++ {
tblview.scrollToRowAtIndexPath(NSIndexPath(forRow: (i+1) * numberofRowsThatShowOnScreen, inSection: 0), atScrollPosition: UITableViewScrollPosition.Top, animated: false)
tblview.layer.renderInContext(UIGraphicsGetCurrentContext())
}
let image:UIImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext();
return image;
}
and after call method like this.
var imageView = UIImageView()
imageView.image = generateImage(tableView)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…