Jimmy's iOS

iOS) 다크모드 & 라이트 모드 막기 본문

iOS

iOS) 다크모드 & 라이트 모드 막기

Jimmy Youn 2021. 10. 3. 22:56

다크모드와 라이트모드 , 둘 중 한가지만 지원되도록 하고 싶다면 window 를 설정해줄때 overrideUserInterfaceStyle 에서 설정을 주면 됩니다. 

 

  •  window?.overrideUserInterfaceStyle = .light
  •  window?.overrideUserInterfaceStyle = .dark
import UIKit

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

  var window: UIWindow?

  func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    guard let scene = (scene as? UIWindowScene) else { return }
    window = UIWindow(windowScene: scene)
    window?.rootViewController = ViewController()
    window?.backgroundColor = .white
    window?.overrideUserInterfaceStyle = .light // 라이트모드만 지원
//    window?.overrideUserInterfaceStyle = .dark // 다크모드만 지원
    window?.makeKeyAndVisible()
    }
  }