簡體   English   中英

將UIView變成UIImage

[英]Turn a UIView into a UIImage

如何將UIView(以子視圖作為UIImageViews)以編程方式轉換為UIImage?

這是常見的做法嗎?

似乎您想要特定視圖的“屏幕快照”?

UIGraphicsBeginImageContext(view.bounds.size); 
CGContextRef ctx = UIGraphicsGetCurrentContext();
[view.layer renderInContext:ctx];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

對於在iOS 10+上尋找Swift 4答案的任何人

let renderer = UIGraphicsImageRenderer(bounds: view.bounds)
let image = renderer.image { rendererContext in
    view.layer.render(in: rendererContext.cgContext)
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM