美文网首页
几种把View转化为Image的方法

几种把View转化为Image的方法

作者: 七维树 | 来源:发表于2017-03-23 14:48 被阅读59次

首先开启上下文

if(UIGraphicsBeginImageContextWithOptions != NULL)
{
        UIGraphicsBeginImageContextWithOptions(view.frame.size, NO, 0.0);
} else {
        UIGraphicsBeginImageContext(view.frame.size);
}

然后

[view snapshotViewAfterScreenUpdates:YES]

绘制的方法
方法一 不支持Retina屏幕

[view.layer renderInContext:UIGraphicsGetCurrentContext()];

方法二

[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];

方法三

[view drawLayer:view.layer inContext:UIGraphicsGetCurrentContext()];

相关文章

网友评论

      本文标题:几种把View转化为Image的方法

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