iOS中控件的截屏

Posted 华少不思议

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS中控件的截屏相关的知识,希望对你有一定的参考价值。

+ (UIImage *)imageWithCaputureView:(UIView *)view

{

 

    // 开启位图上下文

    UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 0);

    

    // 获取上下文

    CGContextRef ctx = UIGraphicsGetCurrentContext();

    

    // 把控件上的图层渲染到上下文,layer只能渲染

    [view.layer renderInContext:ctx];

    

    // 生成一张图片

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

    

    // 关闭上下文

    UIGraphicsEndImageContext();

    

    return image;

}

 

以上是关于iOS中控件的截屏的主要内容,如果未能解决你的问题,请参考以下文章