Capturing full screenshot with status bar in iOS programmatically

后端 未结 7 2398
执笔经年
执笔经年 2020-12-14 03:45

I am using this code to capture a screenshot and to save it to the photo album.

-(void)TakeScreenshotAndSaveToPhotoAlbum
{
   UIWindow *window = [UIApplicati         


        
7条回答
  •  伪装坚强ぢ
    2020-12-14 04:37

    The following works for me, capturing the status bar fine (iOS 9, Swift)

    let screen = UIScreen.mainScreen()
    let snapshotView = screen.snapshotViewAfterScreenUpdates(true)
    UIGraphicsBeginImageContextWithOptions(snapshotView.bounds.size, true, 0)
    snapshotView.drawViewHierarchyInRect(snapshotView.bounds, afterScreenUpdates: true)
    let image = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    

提交回复
热议问题