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
UIGraphicsBeginImageContextWithOptions(CGSizeMake(self.tableView.contentSize.width, self.tableView.contentSize.height), YES, 0);
CGFloat originY = 0;
CGRect rectFirst = CGRectMake(0, originY, self.tableView.bounds.size.width, self.view.bounds.size.height);
[self.tableView scrollRectToVisible:rectFirst animated:NO];
[self.tableView drawViewHierarchyInRect:rectFirst afterScreenUpdates:true];
while (originY < self.tableView.contentSize.height) {
CGRect rectSecond = CGRectMake(0, originY, self.tableView.bounds.size.width, self.view.bounds.size.height);
[self.tableView scrollRectToVisible: rectSecond animated:NO];
[self.tableView drawViewHierarchyInRect: rectSecond afterScreenUpdates:true];
originY += self.view.bounds.size.height;
}
CGRect rectFinally = CGRectMake(0, originY, self.tableView.bounds.size.width, self.tableView.contentSize.height - originY);
[self.tableView scrollRectToVisible:rectFinally animated:NO];
[self.tableView drawViewHierarchyInRect:rectFinally afterScreenUpdates:true];
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
It's very important to set animated to NO, and don't block the UI thread