Capture UIView and Save as Image

前端 未结 7 541
孤城傲影
孤城傲影 2020-12-02 19:31

First of i Add the UILable on UIImageView and then after i screenshot the UIView, the image not proper capture the UIView

7条回答
  •  清歌不尽
    2020-12-02 19:53

    You can take the screenshots of any UIView or capture any UIView and save it as an image with below code.

    - (UIImage *)captureView {
    
        //hide controls if needed
        CGRect rect = [self.view bounds];
    
        UIGraphicsBeginImageContext(rect.size);
        CGContextRef context = UIGraphicsGetCurrentContext();
        [self.view.layer renderInContext:context];   
        UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return img;
    
    }
    

提交回复
热议问题