반응형
UIView를 UIImage로 변환하는 방법 2가지
extension UIView {
func snapshot() -> UIImage {
UIGraphicsImageRenderer(bounds: bounds).image { rendererContext in
layer.render(in: rendererContext.cgContext)
}
}
func toImage() -> UIImage {
UIGraphicsBeginImageContextWithOptions(bounds.size, isOpaque, 0)
defer { UIGraphicsEndImageContext() }
drawHierarchy(in: bounds, afterScreenUpdates: true)
return UIGraphicsGetImageFromCurrentImageContext() ?? UIImage()
}
}반응형
'Dev Study > iOS' 카테고리의 다른 글
| SFSymbol의 Monochrome, Hierarchical, Palette, Multicolor Mode (1) | 2023.12.05 |
|---|---|
| Custom Environment (1) | 2023.12.05 |
| @AppStorage에 Date 타입과 Array 타입 사용하기 (0) | 2023.12.04 |
| PassthroughSubject vs CurrentValueSubject (1) | 2023.12.01 |
| iOS 16.4 이후부터 WebView 디버깅 하기 (0) | 2023.11.15 |
| iOS App URL Cache 제거 (0) | 2023.11.10 |
| iOS 16이상에서 TextKit 1을 사용하고자 할때 (0) | 2023.10.22 |
| Application의 KeyWindow 구하기 (0) | 2023.10.15 |

