能把UIView转换为UIImage的方法,别人总结的一个很好用的方法。为方便平时使用,所以在自己的博客上做个备份。多谢原作者。
#pragma mark view转换为image + (UIImage*) imageWithUIView:(UIView*) view{ // 创建一个bitmap的context // 并把它设置成为当前正在使用的context UIGraphicsBeginImageContext(view.bounds.size); CGContextRef currnetContext = UIGraphicsGetCurrentContext(); [view.layer renderInContext:currnetContext]; // 从当前context中创建一个改变大小后的图片 UIImage* image = UIGraphicsGetImageFromCurrentImageContext(); // 使当前的context出堆栈 UIGraphicsEndImageContext(); return image; }