2010-08-20 30 views
4
//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]; 

如何更改“myTitle”的颜色f.e.变蓝了?一些像PeerGuardian这样的应用程序在其列表被禁用时将其状态栏项目标题更改为红色,所以我想这是可能的。如何更改objective-C/Cocoa中状态栏项目标题的颜色?

谢谢!

回答

4

使用NSStatusItem-setAttributedTitle方法,并给予适当的颜色的NSAttributedString

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]; 
+0

非常感谢您!没有问题的工作! – Jozan 2010-08-23 08:31:57