I am trying to export a tableview as an image. I'd like control over the size of that image.
The problem is that the image is as big as the frame of the tableview, which on the iPhone in my case is 320x480 (or some other height). I want it to be bigger. Actually I want to have control over the size of the exported image. For example I don't want to export image 320x480. I need some sort of scale factor. For example I would like to have 2 times bigger image with 2 times more pixels... I hope I explained it well. Here is some code I use for the image creation.
- (UIImageView*)renderTableViewAsImageView {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView cellForRowAtIndexPath:indexPath].hidden = YES;
self.invoiceExportTitle.textColor = [UIColor blackColor];
CGFloat scaleFactor = 1.0;
CGSize pageSize = CGSizeMake(self.tableView.contentSize.width*scaleFactor, self.tableView.contentSize.height*scaleFactor);
UIGraphicsBeginImageContext(pageSize);
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];
[self.tableView.layer renderInContext:UIGraphicsGetCurrentContext()];
NSInteger rows = [self.tableView numberOfRowsInSection:0];
NSInteger numberOfRowsInView = 4;
for (int i=0; i<rows/numberOfRowsInView; i++) {
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:(i+1)*numberOfRowsInView inSection:0]
atScrollPosition:UITableViewScrollPositionTop
animated:NO];
[self.tableView.layer renderInContext:UIGraphicsGetCurrentContext()];
}
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
UIGraphicsEndImageContext();
[self.tableView cellForRowAtIndexPath:indexPath].hidden = NO;
self.invoiceExportTitle.textColor = [UIColor clearColor];
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:NO];
return imageView;
}