How to take a screenshot programmatically on iOS

前端 未结 20 2119
一生所求
一生所求 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:28

    Get Screenshot From View :

    - (UIImage *)takeSnapshotView {
        CGRect rect = [myView bounds];//Here you can change your view with myView
        UIGraphicsBeginImageContextWithOptions(rect.size,YES,0.0f);
        CGContextRef context = UIGraphicsGetCurrentContext();
        [myView.layer renderInContext:context];
        UIImage *capturedScreen = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    
        return capturedScreen;//capturedScreen is the image of your view
    }
    

    Hope, this is what you're looking for. Any concern get back to me. :)

提交回复
热议问题