So I have an NSVisualEffectView
hooked up with a button and some icons. The material
of this view is originally equal to NSVisualEffectMaterialDark
in other words, Vibrant Dark.
The following code I wrote is supposed to do the following:
1) Detect if the view's material is NSVisualEffectMaterialDark
or NSVisualEffectMaterialLight
2) Change the BOOL isDark
to YES/NO respectively
3) Change the view's appearance
, in other words the material
, from Dark to Light / Light to Dark based on the current view.
The problem is that when I run the app and click the button, NSVisualEffectView
's colour changes from a saturated dark to a less one, and not Light as it is supposed to.
What can I do to fix this problem and prevent it from happening?
Note: the NSVisualEffectView
's name is sideBar
, the button's name is lightButton
and isDark
is originally set to YES
.
Here is my code:
-(IBAction)toggleLighting:(id)sender{
if (self.sideBar.material == NSVisualEffectMaterialDark){
_lightButton.title = (@"Dark Mode");
[_lightButton setImage:[NSImage imageNamed:@"Dark Mode Icon"]];
[_lightButton setAlternateImage:[NSImage imageNamed:@"Dark Mode Icon (Alt)"]];
isDark = YES;
NSLog(@"Changed to Light Theme");
} else if (self.sideBar.material == NSVisualEffectMaterialLight){
_lightButton.title = (@"Light Mode");
[_lightButton setImage:[NSImage imageNamed:@"Light Mode Icon"]];
[_lightButton setAlternateImage:[NSImage imageNamed:@"Light Mode Icon (Alt)"]];
isDark = NO;
NSLog(@"Changed to Dark Theme");
}
if (isDark==YES){
_sideBar.material = NSVisualEffectMaterialLight;
isDark = NO;
} else if (isDark==NO) {
_sideBar.material = NSVisualEffectMaterialDark;
isDark = YES;
}
}