1

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

Frankrockz
  • 594
  • 1
  • 6
  • 24
  • 3
    Does this answer your question? [NSStatusItem Button Title to the Right of the Image](https://stackoverflow.com/questions/31250311/nsstatusitem-button-title-to-the-right-of-the-image) – Robbie Trencheny Aug 05 '20 at 23:59

3 Answers3

2
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];
Eugene
  • 547
  • 4
  • 11
2

You can do this without a custom view like this:

button.imagePosition = NSControl.ImagePosition.imageLeft

Thanks to this answer.

Robbie Trencheny
  • 549
  • 1
  • 4
  • 19
1

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

Mert Dümenci
  • 493
  • 1
  • 5
  • 18