美文网首页
[iOS] 视图截屏

[iOS] 视图截屏

作者: manajay | 来源:发表于2018-04-26 14:00 被阅读10次
    + (UIImage *)lj_snapshot:(UIView *)view {
        
        if (!view) {
            view = [UIApplication sharedApplication].keyWindow;
        }
        
        CGSize size = view.bounds.size;
        
        UIGraphicsBeginImageContextWithOptions(size, NO, [UIScreen mainScreen].scale);
        
        CGRect rec = CGRectMake(view.frame.origin.x, view.frame.origin.y, view.bounds.size.width, view.bounds.size.height);
        
        [view drawViewHierarchyInRect:rec afterScreenUpdates:YES];
        
        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
        
        UIGraphicsEndImageContext();
        
        return image;
    }
    

    相关文章

      网友评论

          本文标题:[iOS] 视图截屏

          本文链接:https://www.haomeiwen.com/subject/hvgplftx.html