0

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.

Khaled Annajar
  • 15,542
  • 5
  • 34
  • 45

3 Answers3

2

Use these methods. Just call UIImage *image = [cell screenshot];

- (UIImage *)screenshot
{
    return [self screenshotForRect:self.bounds];
}

- (UIImage *)screenshotForRect:(CGRect) rect
{
    UIGraphicsBeginImageContext(rect.size);
    [[UIColor clearColor] setFill];
    [[UIBezierPath bezierPathWithRect:rect] fill];
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    [self.layer renderInContext:ctx];
    UIImage *anImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();    
    return anImage;
}
Abid Hussain
  • 1,529
  • 1
  • 15
  • 33
1

try something like that:

UIGraphicsBeginImageContext(yourTableViewCellView.bounds.size);
[yourTableViewCellView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

and then you can save the image to data :)

Sebastian Flückiger
  • 5,525
  • 8
  • 33
  • 69
1
- (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;

}
Paras Joshi
  • 20,427
  • 11
  • 57
  • 70