能把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;
}