Skip to content

Instantly share code, notes, and snippets.

@maxsteenbergen
Created May 13, 2013 09:18
Show Gist options
  • Save maxsteenbergen/5567139 to your computer and use it in GitHub Desktop.
Save maxsteenbergen/5567139 to your computer and use it in GitHub Desktop.
This should draw an icon in the Status Bar. It works on my MacBook, but on my iMac it doesn't show an icon. The menulet is there, I can click it: it simply doesn't show the icon.
- (void)drawRect:(NSRect)rect
{
/* NSImage *img = [NSImage imageNamed:@"[email protected]"];
rect = CGRectInset(rect, 2, 3);
NSRect imageRect;
imageRect.origin = NSZeroPoint;
imageRect.size = [img size];
[img drawInRect:rect fromRect:imageRect operation:NSCompositeSourceOver fraction:1];
*/
NSImage *img = [NSImage imageNamed:@"basket.png"];
NSStatusItem *statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
[statusItem setImage:img];
[statusItem setHighlightMode:YES];
[statusItem setEnabled:YES];
}
@tarnfeld
Copy link

I may be wrong, but I seem to remember that you need too keep a reference to the statusItem for it to stay visible... Perhaps stick it into an ivar?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment