Save full screen shot including bars

I am having problems with the following code, but only a snapshot of my UITableView, and not the whole screen with navigation and tabs ...

I need a full screen capture, including navigation and tab bars. Any help was greatly appreciated.

- (UIImage*)captureView:(UIView *)view { CGRect rect = [[UIScreen mainScreen] bounds]; UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); [view.layer renderInContext:context]; UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return img; } 
+6
source share
2 answers

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(); 
+12
source

Swift version 3.0, if anyone needs

 func getScreenShot() -> UIImage { let layer : CALayer = (UIApplication.shared.keyWindow?.layer)! let scale : CGFloat = UIScreen.main.scale UIGraphicsBeginImageContextWithOptions(layer.frame.size, false, scale) layer.render(in: UIGraphicsGetCurrentContext()!) let image = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return image! } 
+1
source

Source: https://habr.com/ru/post/943738/


All Articles