Reputation: 1562
I have an application that's laid out using an UITableView. The interface takes up more than just the screen, so there's some area that can be scrolled to. I would like some screenshots of the entire view (including the non-visible area) to use for documentation and soliciting feedback from my customer.
Is there programmatic way to get an image of the entire view? I don't think there would be a way on the device to do this, but maybe there is.
Upvotes: 5
Views: 9291
Reputation: 7247
Take a screenshot of the whole table view and not just visible cells. This approach doesn't require scrolling the table view and taking many screenshots and putting them together.
Works well with table view footer and header.
CGRect frame = _tableView.frame;
frame.size.height = _tableView.contentSize.height;//the most important line
_tableView.frame = frame;
UIGraphicsBeginImageContext(_tableView.bounds.size);
[_tableView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData * data = UIImagePNGRepresentation(image);
Upvotes: 1
Reputation: 976
You can actually scroll the tableview. The following code works perfect in my application. But it may take a white for making the screenshot. You may refer to this to see if anyone improved.
//viewController is your UITableViewController
UIGraphicsBeginImageContext(viewController.tableView.contentSize);
[viewController.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];
[viewController.tableView.layer renderInContext:UIGraphicsGetCurrentContext()];
int rows = [viewController.tableView numberOfRowsInSection:0];
int numberofRowsInView = 7;
for (int i =0; i < rows/numberofRowsInView; i++) {
[viewController.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:(i+1)*numberofRowsInView inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];
[viewController.tableView.layer renderInContext:UIGraphicsGetCurrentContext()];
}
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Upvotes: 4
Reputation: 314
Just pasting some code I used in my app. It draws a view to an image (potentially scaling). Maybe you could programmaticaly scroll the table and stitch the images together in the end or something similar:
+ (UIImage *)captureView: (UIView *)view inSize: (CGSize)size
{
UIGraphicsBeginImageContext(size);
CGSize viewSize = view.frame.size;
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextScaleCTM( context, size.width/viewSize.width, size.height/viewSize.height);
[view.layer renderInContext: UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return viewImage;
}
Hope it helps
Upvotes: 6
Reputation: 64428
As Jasarien said, a UITableView has no off screen elements. It's just a stage illusion that creates the appearance of single long element.
If you want to create an image of long (i.e. offscreen) table, you should take screenshots of the table at different scroll positions and then Photoshop/GIMP/insert-graphics-app the screenshots into one long graphic.
Upvotes: 1
Reputation: 58458
With a table view on the iphone, there is no "extra" area to scroll to. The table view is as big as the screen, and as new cells are scrolled into view, they're created on demand, while old cells that are scrolled off screen are deallocated.
Upvotes: 1