美文网首页
如何截图保存图片

如何截图保存图片

作者: 姀影 | 来源:发表于2017-11-01 16:32 被阅读11次

新建一个UIImage类别
在类别中建一个+方法
.h中
+ (UIImage *)caputureViewForImage:(UIView *)view;
.m中
+ (UIImage *)caputureViewForImage:(UIView *)view{
// 开启位图上下文
UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 0);
// 获取上下文
CGContextRef ctx = UIGraphicsGetCurrentContext();
// 把控件上的图层渲染到上下文,layer只能渲染
[view.layer renderInContext:ctx];
// 生成一张图片
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
// 关闭上下文
UIGraphicsEndImageContext();
return image;
}

相关文章

网友评论

      本文标题:如何截图保存图片

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