如何設置NSStatus項目的標題文字顏色的文字顏色?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];
好,我已經試過@ Vervious的帖子,這是我並沒有什麼改變。
-(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];
}
哇,嗯。 Objective-C調用AppleScript調用shell腳本。你知道你可以在純Objective-C中做到這一點,對吧?瘋狂的東西叫'NSDateFormatter'... – 2012-08-03 19:05:28