반응형
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()
}
}
반응형
'iOS > Tip' 카테고리의 다른 글
휴대전화번호 포멧(000-0000-0000)으로 만들기 (0) | 2024.01.16 |
---|---|
UITextField hyphen(-) 연속 입력시 en dash(–)로 변경되는것 막기 (0) | 2023.12.14 |
SFSymbol의 Monochrome, Hierarchical, Palette, Multicolor Mode (1) | 2023.12.05 |
@AppStorage에 Date 타입과 Array 타입 사용하기 (0) | 2023.12.04 |
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 |