iOS 如何把view转成image

Sky飞羽

关注

阅读 58

2021-09-22

- (UIImage*) imageWithUIView:(UIView*) view

{

UIGraphicsBeginImageContext(view.bounds.size);

CGContextRef context = UIGraphicsGetCurrentContext();

[view.layer renderInContext:context];

UIImage* tImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return tImage;

}

注意:此方法不是线程安全的。使用时需注意!

精彩评论(0)

0 0 举报