iosswiftxcodeios-darkmode

How to switch programmatically to dark mode swift


How can I make a switch to change programatically to dark or light mode in my iOS app? I'm using Swift.


Solution

  • You can override the style for single views or view controller using the overrideUserInterfaceStyle property. But since the window is also a view, you can set that on your main window to force it into light or dark mode:

    window.overrideUserInterfaceStyle = .dark