Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable dark mode for mac OSX App in Swift

Is it possible to disable the dark mode for the mac app?

I only want it to show the default style of my app, even if the user uses dark mode on his mac.

I am using a popover.

Tried to use this: self.popover.appearance = NSAppearanceNameAqua but it tells me: cannot assign value of type String to type NSApperance.

like image 729
fredsco Avatar asked May 26 '16 08:05

fredsco


People also ask

How do I turn off Dark Mode in Swift app?

To control an interface style for an entire app, you simply set UIUserInterfaceStyle (Appearance) key in your Info. plist file. You can assign it to either Light or Dark value to force a light and dark user interface style. Set Appearance (UIUserInterfaceStyle) key to Light will disable dark mode for an entire app.

How do I turn off dark app mode on Mac?

Dark mode can also be quickly enabled from Control Center. Click the switch icon in the menu bar and click Display, then choose Dark Mode to switch the feature on and off.

Can you turn Dark Mode off for certain apps?

Tap the hamburger menu in the top-right (Android) or bottom-right (iOS) corner, scroll down and select Settings & Privacy > Dark Mode. You can then turn it on or off, or make the app dependent on your phone's system-wide theme.

How do I restrict dark app mode?

In the menu, find Settings and tap on it. Tap on General. Find the Theme option, tap it, and you will get to choose between Light and Dark. There is a third option that will set the theme in accordance with your device's global dark mode settings.


2 Answers

You'll need initialize the name first:

popover.appearance = NSAppearance(named: NSAppearanceNameAqua)

You were close.

Edit for Swift 4.1:

popover?.appearance = NSAppearance(named: NSAppearance.Name.aqua)
like image 64
l'L'l Avatar answered Sep 21 '22 02:09

l'L'l


You can disable support for dark mode in the Info.plist of your app:

Opt Out of Dark Mode

Apps linked against macOS 10.14 or later should support both light and dark appearances. If you build your app against an earlier SDK, you can still enable Dark Mode support by including the NSRequiresAquaSystemAppearance key (with a value of false) in your app's Info.plis file. Do so only if your app's appearance looks correct when running in macOS 10.14 and later with Dark Mode enabled.

If you need extra time to work on your app's Dark Mode support, you can temporarily opt out by including the NSRequiresAquaSystemAppearance key (with a value of true) in your app’s Info.plist file. Setting this key to true causes the system to ignore the user's preference and always apply a light appearance to your app.

Source: https://developer.apple.com/documentation/appkit/nsappearancecustomization/choosing_a_specific_appearance_for_your_app

like image 22
Pieter Claerhout Avatar answered Sep 20 '22 02:09

Pieter Claerhout