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-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 に答える