Reputation: 827
Using XCode Version 9.4.1 (9F2000) I would like to dynamically allow the user to change the theme of a Mac app from Light to Dark etc, but I'm falling at the first hurdle.
I tried putting the following code in both applicationDidFinishLaunching
and ViewController's viewDidLoad
methods, but neither caused the theme to change to Dark theme.
NSAppearance* appearance = [NSAppearance appearanceNamed:NSAppearanceNameVibrantDark];
[self.window setAppearance:appearance];
I was unable to find an Apple sample showing how to do this programmatically. Can anyone point out what I've overlooked??
Upvotes: 0
Views: 1303
Reputation: 827
I was able to get it to work by moving my code to the controller's viewWillAppear
(as per sample below). Then everything is themed correctly!
- (void)viewWillAppear {
[super viewWillAppear];
NSAppearance* appearance = [NSAppearance appearanceNamed:NSAppearanceNameVibrantDark];
[self.view.window setAppearance:appearance];
}
Upvotes: 3