6
//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”的颜色更改为蓝色?

当列表被禁用时,像 PeerGuardian 这样的应用程序会将其状态栏项目标题更改为红色,所以我想这是可能的。

4

2 回答 2

5

使用NSStatusItem's-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];
于 2010-08-21T03:49:45.973 回答
2

斯威夫特 4 版本:

let attributes = [NSAttributedStringKey.foregroundColor: NSColor.blue]
let attributedText = NSAttributedString(string: "myTitle", attributes: attributes)

let statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
statusItem.attributedTitle = attributedText
于 2018-04-05T17:37:30.980 回答