本文介绍了如何在Objective-C /可可中更改状态栏项目标题的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
//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的颜色变成蓝色?
How to change color of "myTitle" to blue?
像PeerGuardian这样的某些应用程序在禁用列表时将其状态栏项目标题更改为红色,所以我想这是有可能的。
Some applications like PeerGuardian change their status bar item titles to red when their lists are disabled, so I guess this is somehow possible.
推荐答案
使用 NSStatusItem
的 -setAttributedTitle
方法,然后给它一个适当颜色的 NSAttributedString
:
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];
这篇关于如何在Objective-C /可可中更改状态栏项目标题的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!