Steve Steve - 1 year ago 73
iOS Question

Save full screenshot including bars

I am having problems with the following code only takes a photo of my UITableView only and not the entire screen with the navigation and tab bars...

I would like the full screen capturing including navigation and tab bars. Any help greatly appreciated.

- (UIImage*)captureView:(UIView *)view
CGRect rect = [[UIScreen mainScreen] bounds];
CGContextRef context = UIGraphicsGetCurrentContext();
[view.layer renderInContext:context];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
return img;

Answer Source

The following code worked for me a couple of months ago:

CALayer *layer = [[UIApplication sharedApplication] keyWindow].layer;
CGFloat scale = [UIScreen mainScreen].scale;
UIGraphicsBeginImageContextWithOptions(layer.frame.size, NO, scale);

[layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();