How to set dark mode for NSToolbar in macOS Catalyst app?

481 Views Asked by At

In my iOS/macOS app the user can choose between a light and a dark appearance.

This is done by setting the overrideUserInterfaceStyle of the app window, for example

window.overrideUserInterfaceStyle = .dark

It works fine on iOS/iPadOS.

On macOS (Catalyst) the app uses an NSToolbar, which always appears in the mode chosen in the system settings, regardless what ist set for the overrideUserInterfaceStyle of the window (see screenshot).

Since this is not a good visual impression, I would like to know how I can set light/dark mode for the NSToolbar too.

app in dark mode with NSToolbar in light mode

2

There are 2 best solutions below

2
iosdeveloper On BEST ANSWER

This can be done by adding an macOS plugin which has access to the whole AppKit API. Instructions can be found here: How to Access the AppKit API from Mac Catalyst Apps

Then you can set the desired appearance there at runtime, for example:

NSApplication.shared.appearance = NSAppearance(named: .darkAqua)
4
Adam On

Add UIUserInterfaceStyle with a value Dark to your app’s Info.plist. That will force the whole app to dark mode on iOS 13+ and Mac Catalyst (you won’t need to set overrideUserInterfaceStyle).

Docs: https://developer.apple.com/documentation/bundleresources/information_property_list/uiuserinterfacestyle