how to take a screenshot of the iPhone programmatically?

前端 未结 11 1859
谎友^
谎友^ 2020-11-28 08:01

Is it possible in objective C that we can take the screen shot of screen and stored this image in UIImage.

11条回答
  •  囚心锁ツ
    2020-11-28 08:16

    // 100% Work

    - (UIImage *)screenshot
    {                   
      UIGraphicsBeginImageContextWithOptions(self.main_uiview.bounds.size, NO, 2.0f);
      [self.main_uiview drawViewHierarchyInRect:_main_uiview.bounds afterScreenUpdates:YES];
    
      UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
      UIGraphicsEndImageContext();
    
      return image;
    }
    

提交回复
热议问题