How to take a screenshot programmatically on iOS

前端 未结 20 2083
一生所求
一生所求 2020-11-22 01:42

I want a screenshot of the image on the screen saved into the saved photo library.

20条回答
  •  不知归路
    2020-11-22 02:18

    This will save a screenshot and as well return the screenshot too.

    -(UIImage *)capture{
        UIGraphicsBeginImageContext(self.view.bounds.size);
        [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
        UIImage *imageView = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        UIImageWriteToSavedPhotosAlbum(imageView, nil, nil, nil); //if you need to save
        return imageView;
    }
    

提交回复
热议问题