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
add render method to UITableView through category
- (UIImage *)render {
//save the origin infos for later to restore
CGPoint originContentOffset = self.contentOffset;
//force jump to table view's top
self.contentOffset = CGPointZero;
UIGraphicsBeginImageContext(self.contentSize);
CGContextRef *ctx = UIGraphicsGetCurrentContext();
//render header
[self.tableHeaderView.layer renderInContext:ctx];
//render sections
NSInteger numberOfSections = [self numberOfSections];
for (int section = 0; section < numberOfSections; section++) {
NSInteger numberOfRows = [self numberOfRowsInSection:section];
for (int row = 0; row < numberOfRows; row++) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
//check cell is visible
if ([self cellForRowAtIndexPath:indexPath]) {
[self scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:false];
[self.layer renderInContext:ctx];
}
}
}
//render footer
[self.tableFooterView.layer renderInContext:ctx];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//restore infos
self.contentOffset = originContentOffset;
return image;
}