views:

35

answers:

1
//Create the NSStatusBar and set its length
statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain];

[statusItem setHighlightMode:YES];
[statusItem setTitle:@"myTitle"];
[statusItem setToolTip:@"myToolTip"];
[statusItem setMenu:statusMenu];
[statusItem setEnabled:YES];

How to change color of "myTitle" f.e. to blue? Some applications like PeerGuardian changes its status bar item title to red when its lists are disabled, so I guess this is somehow possible.

Thank you!

+1  A: 

Use NSStatusItem's -setAttributedTitle method, and give it an NSAttributedString of the appropriate color:

NSDictionary *titleAttributes = [NSDictionary dictionaryWithObject:[NSColor blueColor] forKey:NSForegroundColorAttributeName];
NSAttributedString* blueTitle = [[NSAttributedString alloc] initWithString:@"myTitle" attributes:titleAttributes];

statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain];
[statusItem setAttributedTitle:blueTitle];
[blueTitle release];
andyvn22
Thank you very much! Works with no problems!
Jozan