0

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.

Henhen1227
  • 392
  • 1
  • 3
  • 12
  • You could also have a look at the following question: https://stackoverflow.com/questions/56537855/is-it-possible-to-opt-out-of-dark-mode-on-ios-13/56546554 – finebel Aug 16 '20 at 17:45
  • When I do `overrideUserInterfaceStyle = .dark` just the one viewController changes. Also, the TabBar doesn't change. When I use `window.overrideUserInterfaceStyle = .dark` i get this error "Use of unresolved identifier 'window'" – Henhen1227 Aug 16 '20 at 17:46
  • You have to put this line of code inside the ```willConnectTo``` method inside of your ```SceneDelegate``` file. – finebel Aug 16 '20 at 17:49
  • 1
    @Henhen1227 Happy to help! (You could also upvote my comment ;-)) – finebel Aug 16 '20 at 17:57

1 Answers1

6

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
}
Henhen1227
  • 392
  • 1
  • 3
  • 12
Predrag Samardzic
  • 2,661
  • 15
  • 18