Установить цвет текста заголовка элемента 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];

}

1 ответ

Установите атрибутивный заголовок элемента статуса на атрибутивную строку по вашему выбору. Например

NSDictionary *attributes = [NSDictionary
                            dictionaryWithObjectsAndKeys:
                            [NSColor redColor], NSForegroundColorAttributeName, nil];
NSAttributedString *colouredTitle = [[NSAttributedString alloc] 
             initWithString:[timeWSeconds stringValue]]
             attributes:attributes];
[statusItem setAttributedTitle:colouredTitle];
Другие вопросы по тегам