热门搜索 :
考研考公
您的当前位置:首页正文

几种把View转化为Image的方法

来源:东饰资讯网

首先开启上下文

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()];
Top