#import <QuartzCore/QuartzCore.h>//记住要加上这个头文件!!!

- (UIImage*)convertViewToUIImage:(UIView*)v
{
    UIGraphicsBeginImageContext(v.bounds.size);
    CGContextRef currentContext = UIGraphicsGetCurrentContext();
    [v.layer renderInContext:currentContext];
      // 从当前context中创建一个改变大小后的图片  
    UIImage  *image = UIGraphicsGetImageFromCurrentImageContext();
        // 使当前的context出堆栈  
    UIGraphicsEndImageContext();
    return image;
}

使用方法:

UIView *view =[[UIView alloc]init];

UIImage *image = [self convertViewToUIImage:view];

 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-04
  • 2022-12-23
  • 2021-07-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-29
  • 2022-12-23
  • 2022-01-20
  • 2022-12-23
相关资源
相似解决方案