Search code examples
swiftxcodeios-darkmode

Change between Light and Dark mode for entire app


I want to have a dark mode option within the settings page of my Xcode swift app. Is it possible to change dark mode just for the app, on all view controllers in the app? I have my dark colors selected in Assets.xcassets

I understand that I can use overrideUserInterfaceStyle = .dark but this only changes the one viewController. I want it to switch the entire app.


Solution

  • You could set it on your app's window (it is also a view):

    window.overrideUserInterfaceStyle = .dark
    

    Edit: Add to SceneDelegate file in the willConnectTo func

    For example:

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
            window?.overrideUserInterfaceStyle = .light
    }