Capture UIView and Save as Image

前端 未结 7 556
孤城傲影
孤城傲影 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:38

    Take snapshot of a UIView

    pass your view to this function it will handle everything itself( No need to set bounds or frames)

    - (UIImage *)takeSnapshotOfView:(UIView *)view
    {
        UIGraphicsBeginImageContext(CGSizeMake(view.frame.size.width, view.frame.size.height));
        [view drawViewHierarchyInRect:CGRectMake(0, 0, view.frame.size.width, view.frame.size.height) afterScreenUpdates:YES];
        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    
        return image;
    }
    

提交回复
热议问题