Как установить цвет текстовой метки NSButtonCell - PullRequest
5 голосов
/ 14 октября 2010

Как установить цвет текста метки (заголовка) NSButtonCell, то есть ячейки столбца для табличного представления?В моем случае это клетка кнопки флажка.(Возможно ли использование IB?)

Ответы [ 2 ]

12 голосов
/ 01 января 2013

Попробуйте, я думаю, что это идеальный вариант.

NSColor *color = [NSColor redColor];
NSMutableAttributedString *colorTitle =
    [[NSMutableAttributedString alloc] initWithAttributedString:[button attributedTitle]];

NSRange titleRange = NSMakeRange(0, [colorTitle length]);

[colorTitle addAttribute:NSForegroundColorAttributeName
                   value:color
                   range:titleRange];

[button setAttributedTitle:colorTitle];
9 голосов
/ 14 октября 2010

Вы можете попробовать атрибутное строковое значение.

NSColor *txtColor = [NSColor redColor];
NSFont *txtFont = [NSFont boldSystemFontOfSize:14];
NSDictionary *txtDict = [NSDictionary dictionaryWithObjectsAndKeys:
        txtFont, NSFontAttributeName, txtColor, NSForegroundColorAttributeName, nil];
NSAttributedString *attrStr = [[[NSAttributedString alloc]
        initWithString:@"Hello!" attributes:txtDict] autorelease];
[[attrStrTextField cell] setAttributedStringValue:attrStr];
[attrStrTextField updateCell:[attrStrTextField cell]];
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...