1
我有一個是由其他子視圖UIView
。從UIView的獲取圖像,無父視圖
這UIView
不是在應用程序中的任何其它視圖的子視圖。
我可以從中得到UIView
圖像(UIImage
)?還是應該從顯示的視圖中引用它?
我有一個是由其他子視圖UIView
。從UIView的獲取圖像,無父視圖
這UIView
不是在應用程序中的任何其它視圖的子視圖。
我可以從中得到UIView
圖像(UIImage
)?還是應該從顯示的視圖中引用它?
你並不需要把它顯示出來。 該視圖對象只是通過這個功能,你會得到的圖像
+ (UIImage *) imageWithView:(UIView *)view
{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
func imageWithView (view: UIView)->UIImage
{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, false, 0.0)
view.layer.renderInContext(UIGraphicsGetCurrentContext())
newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return newImage
}
這是swift
版本
我已經意識到,有一個半小時..感謝張貼的問題後, –