4

I tried toggle the dark mode, I know Swift 4 or 5 I use the code:

overrideUserInterfaceStyle = .dark

But in SwiftUI, seem nothing way I can do that...how can I toggle the dark mode rest of app? I tried do many method and search everywhere but couldn't find any luck. Even I tried use didSet but no luck, it give me the error.

Any suggestion?

1 Answers1

5

If you want to force dark mode for the whole app you can add the User Interface Style to the Info.plist and set it to Dark

enter image description here

You can also add the following line to the Scene/App Delegate

window?.overrideUserInterfaceStyle = .dark

egmoll7
  • 119
  • 3
  • I would like to have both support...I am trying to figure out how to add the toggle so I can set three different dark mode - Automatic, Dark, and Light. On my old app with Swift 4, I have no problem but with SwiftUI, I am trying to figure out how to toggle Dark Mode on my new app –  Jun 23 '20 at 01:11
  • 7
    The plist property `User Interface Style` is no longer available or has been renamed to `Appearance` – Marco Boerner Mar 07 '21 at 21:41
  • To add a row to pList, right-click, then select "Add Row". Once the row is added, the key column will have a drop-down where the relevant key (e.g. Appearance) can be selected. – RudyF Oct 22 '21 at 17:01