David Ben Ari David Ben Ari - 1 month ago 7x
iOS Question

creating a UIImage from a UITableView

Is there a way to create an

out of a

I know about this piece of code that will draw a
out of a given

-(UIImage*) makeImageOutOfView:(UIView*)view {


[view.layer renderInContext:UIGraphicsGetCurrentContext()];

UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();

return viewImage;

but it would only create an image with the size of the table's frame. I would like to create an image that will display the whole table's content. Another problem is that not only that the created image was limited to the table's frame, but when creating the image after scrolling the table had very weird outcomes (only the visible cells out of the first 6 where shown in the image and that's all, the other visible cells were not drawn..)

EDIT - i want to create an image that was drawn out of the content of a tableView, not setting the tableView's background to display an image..


i just Create a DEMO for you and hope its helps you you can capture table image like this way:-

    [tbl reloadData];

    CGRect frame = tbl.frame;
    frame.size.height = tbl.contentSize.height;
    tbl.frame = frame;

    [tbl.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *saveImage = UIGraphicsGetImageFromCurrentImageContext();

    NSData *imageData = UIImagePNGRepresentation(saveImage);
    NSFileManager *fileMan = [NSFileManager defaultManager];

    NSString *fileName = [NSString stringWithFormat:@"%d.png",1];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *pdfFileName = [documentsDirectory stringByAppendingPathComponent:fileName];
    [fileMan createFileAtPath:pdfFileName contents:imageData attributes:nil];


This is a Screen Shot of capture image:-

enter image description here

capture image contain full of table cell top to bottom please download the demo of it:-