9

Hi I developed a cocoa status app. when I put a long title for example , it can't be shown and if i put an image as icon too it can't be shown , but if i put a small title it works correctly. How can I fix this problem and make the image shown?

statusItem = [[[NSStatusBar systemStatusBar] 
    statusItemWithLength:NSSquareStatusItemLength] retain];    

[statusItem setMenu:menu]; 
//[statusItem setTitle:@"Notif "]; 
[statusItem setImage:[NSImage imageNamed:@"image"]]; 
[statusItem setHighlightMode:YES];
jamesmortensen
  • 33,636
  • 11
  • 99
  • 120
user1503496
  • 191
  • 4
  • 13

1 Answers1

9

Basically

NSStatusItem *statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
NSImage* icon = [NSImage alloc] initWith ...]
[statusItem setImage:icon];

But your image has to be at a correct size (less than 20*20)

Matthieu Riegler
  • 31,918
  • 20
  • 95
  • 134
  • statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain]; [statusItem setMenu:menu]; //[statusItem setTitle:@"Notif "]; [statusItem setImage:[NSImage imageNamed:@"image"]]; [statusItem setHighlightMode:YES]; this is my code and i had added the image to other sources folder – user1503496 Jul 10 '12 at 12:59
  • how can i make a size less then 20*20 ? – user1503496 Jul 10 '12 at 13:07
  • 1
    [icon setSize:NSMakeSize(width,height)]. And be sure [NSImage imageNamed:@"image"] does not return nil. – Matthieu Riegler Jul 10 '12 at 16:22
  • 2
    The image, for non-Retina, has a maximum size of 21x21 rather than 20x20. For retina, the maximum is 41x41; see [my blog post](http://alastairs-place.net/blog/2013/07/23/nsstatusitem-what-size-should-your-icon-be/) for more. – al45tair Jul 23 '13 at 11:06