如何设置NSStatus项目标题文字颜色的文字颜色?
这是我用来设置statusItem:
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:@"set the timeWSeconds to do shell script \"/bin/date '+%a %b %I:%M:%S %p'\""];
NSAppleEventDescriptor *timeWSeconds = [[script executeAndReturnError:nil]stringValue];
[statusItem setTitle:timeWSeconds];
-(IBAction)timeWSeconds:(id)sender
{
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:@"set the timeWSeconds to do shell script \"/bin/date '+%a %b %d %I:%M:%S %p'\""];
NSAppleEventDescriptor *timeWSeconds = [[script executeAndReturnError:nil]stringValue];
[statusItem setTitle:timeWSeconds];
NSDictionary *attributes = [NSDictionary
dictionaryWithObjectsAndKeys:
[NSColor redColor], NSForegroundColorAttributeName, nil];
NSAttributedString *colouredTitle = [[[NSAttributedString alloc]
initWithString:[timeWSeconds stringValue]]
attributes:attributes];
[statusItem setAttributedTitle:colouredTitle];
}
答案 0 :(得分:2)
将状态项的属性标题设置为您选择的属性字符串。 E.g。
NSDictionary *attributes = [NSDictionary
dictionaryWithObjectsAndKeys:
[NSColor redColor], NSForegroundColorAttributeName, nil];
NSAttributedString *colouredTitle = [[NSAttributedString alloc]
initWithString:[timeWSeconds stringValue]]
attributes:attributes];
[statusItem setAttributedTitle:colouredTitle];