Adding both the title and image to an NSStatusItem

1k views Asked by At

I've been trying to figure out how to add both text and an image to an NSStatusItem. Here is a mockup of what i'm trying to do:

http://cl.ly/GjTO

I've tried using the statusIetm.view and adding a subview, I've tried setting both the title and image property for fun even though I know that doesn't work. 'm not trying to add a a custom window the the Status Item, but the temperature and condition icon found in the first image. If anyone has any idea, I'd love to hear them.

Thanks

3

There are 3 answers

1
Mert Dümenci On BEST ANSWER

Try creating a custom NSView and setting it with [statusItem setView:myCustomView];

1
Dsda On
statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
NSImage *statusImage = [NSImage imageNamed:@"icon.png"]; // must be 19x19 max
[statusItem setImage:statusImage];
NSImage *altStatusImage = [NSImage imageNamed:@"icon.png"];
[statusItem setAlternateImage:altStatusImage];
[statusItem setHighlightMode:YES];
[statusItem setAttributedTitle:attrString];
[statusItem setTitle:@"Loading..."];
[statusItem setMenu:statusMenu];
0
Robbie Trencheny On

You can do this without a custom view like this:

button.imagePosition = NSControl.ImagePosition.imageLeft

Thanks to this answer.