My application have some UI issues in Mac Os Mojave.Some labels and buttons text content are not visible when I switched to Dark Mode.So I did one workaroud using following code.
var interfaceStyle = NSUserDefaults.StandardUserDefaults.StringForKey("AppleInterfaceStyle");
if (interfaceStyle == "Dark") {
label.textcolor = NSColor.White;
}
This fixes the issues,But if I switched back to light mode in between the application is using the label color will not change.I need to restart the application to read the code and displaying the label with default color.
Could Any one faced this issue ? Is there any delegate method that hits when the user changes the Appearance mode(Dark & Light) of Mac Os Mojave ?
You can use
KVO
to track theme changes (AppleInterfaceThemeChangedNotification
).A few class level "constants":
Export method for the ObjC selector to call:
Add observer request to notification center:
Note: I typically register this in
AppDelegate.DidFinishLaunching
Remove the observer if you no longer need it:
BTW: The
NSDistributedNotificationCenter.DefaultCenter.AddObserver
helpers/overloads do not work properly in this instance...