Skip to content

Instantly share code, notes, and snippets.

@TuenTuenna
Last active November 3, 2022 08:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TuenTuenna/d1ed499c1e8b1f776ce8ddbaf94fd11d to your computer and use it in GitHub Desktop.
Save TuenTuenna/d1ed499c1e8b1f776ce8ddbaf94fd11d to your computer and use it in GitHub Desktop.
SwiftUi 노치 디자인 여부 체크 입니다

노치 디자인 여부 체크

import Foundation
import UIKit

// UIDevice 익스텐션으로 만들어줍니다.
extension UIDevice {
    var hasNotch: Bool {
        
        let scenes = UIApplication.shared.connectedScenes
        let windowScenes = scenes.first as? UIWindowScene
        let window = windowScenes?.windows
        
        let bottom = window?.filter {$0.isKeyWindow}.first?.safeAreaInsets.bottom ?? 0
        
        return bottom > 0
    }
}

사용 예시

SomeView().background(UIDevice.current.hasNotch ? Color.red : Color.yellow)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment