把指定view转化为图片

+(UIImage *)captureImageInView:(UIView *)view {
    //1.开启上下文
    
    UIGraphicsBeginImageContext(view.frame.size);
    
    //2.绘制图形
    
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    
    //把layer上的内容绘制到上下文当中
    
    [view.layer renderInContext:ctx];
    
    UIImage* newImage =UIGraphicsGetImageFromCurrentImageContext();
    
    //3.关闭上下文
    
    UIGraphicsEndImageContext();
    return newImage;
}

你可能感兴趣的:(把指定view转化为图片)