투케이2K

189. (ios/swift) userInterfaceStyle 사용해 사용자 디스플레이스 설정 Light (라이트) , Dark (다크) 모드 확인 실시 본문

IOS

189. (ios/swift) userInterfaceStyle 사용해 사용자 디스플레이스 설정 Light (라이트) , Dark (다크) 모드 확인 실시

투케이2K 2022. 9. 14. 16:49
반응형

[개발 환경 설정]

개발 툴 : XCODE

개발 언어 : SWIFT

 

[소스 코드]

    // MARK: - [테스트 함수 정의]
    func testMain() {
        print("")
        print("===============================")
        print("[ViewController >> testMain() :: 테스트 함수 수행]")
        print("===============================")
        print("")
        
        
        /*
         // -----------------------------------
         [요약 설명]
         // -----------------------------------
         1. userInterfaceStyle 는 장치 인터페이스 어둡기 , 밝기를 확인할 수 있습니다
         // -----------------------------------
         2. userInterfaceStyle 는 iOS 12.0 이상 사용할 수 있습니다
         // -----------------------------------
         */
        
        
        if traitCollection.userInterfaceStyle == .light {
            print("")
            print("===============================")
            print("[ViewController >> testMain() :: 사용자 디스플레이 설정 확인]")
            print("[display :: Light Mode]")
            print("===============================")
            print("")
        } else {
            print("")
            print("===============================")
            print("[ViewController >> testMain() :: 사용자 디스플레이 설정 확인]")
            print("[display :: Dark Mode]")
            print("===============================")
            print("")
        }
    }
    
    
    
    
    // MARK: - [사용자 터치 이벤트 발생 시 디스플레이 설정 확인 실시]
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        
        if traitCollection.userInterfaceStyle == .light {
            print("")
            print("===============================")
            print("[ViewController >> touchesBegan() :: 사용자 디스플레이 설정 확인]")
            print("[display :: Light Mode]")
            print("===============================")
            print("")
        } else {
            print("")
            print("===============================")
            print("[ViewController >> touchesBegan() :: 사용자 디스플레이 설정 확인]")
            print("[display :: Dark Mode]")
            print("===============================")
            print("")
        }
    }
 

[결과 출력]


반응형
Comments