iphoneobjective-ciosuitableviewprintscreen

How can I export UITableViewCell into image?


I need to export UITableViewCell into an image PNG or anything so I can send it as a print screen image embedded in email body using the MFMailComposerViewController.


Solution

  • - (UIImage *)captureCell {
    
        //hide controls if needed
    CGRect rect = [yourTableCell bounds];
    
        UIGraphicsBeginImageContext(rect.size);
        CGContextRef context = UIGraphicsGetCurrentContext();
        [yourTableCell.layer renderInContext:context];   
        UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return img;
    
    }