Programmatically take a screenshot of specific area

后端 未结 4 1540
半阙折子戏
半阙折子戏 2020-12-24 15:06

Like you can see in my code, I take a screenshot and save it to the photo album.

//for retina displays
if ([[UIScreen mainScreen] respondsToSelector:@selecto         


        
4条回答
  •  生来不讨喜
    2020-12-24 15:30

    - (void)drawRect:(CGRect)rect {
      UIGraphicsBeginImageContext(self.bounds.size);    
      [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
      UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
      UIGraphicsEndImageContext();
      UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);  
    }
    

    You could call this to your view :]

提交回复
热议问题