Image of an invalid NSStatusBarButton template

I'm trying to move my app to the status bar to use NSStatusBarButton

in Yosemite instead of a custom view, but I can't get the template image to work.

I am setting up NSStatusItem

like this:

self.statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
self.statusItem.button.imagePosition = NSImageLeft;
self.statusItem.button.target = self;
self.statusItem.button.action = @selector(clickButton:);

      

then i set image and title later like so,

self.statusItem.button.title = [self statusItemTitleForLocation:location];

NSImage *image = [self statusItemImageForLocation:location];
[image setTemplate:YES];
self.statusItem.button.image = image;

      

The images I'm using are PNG files with only black and transparent colors.

This seems to be a pretty random way of displaying it. Sometimes it displays black as intended and going into dark mode will make it look pale. But when you turn off dark mode, the text and image remain white. At other times, the app will launch (with dark mode off) and the text and image will be white and remain white even after switching dark mode to then.

Any ideas?

+3


source to share





All Articles