开发者

How do I set the color of an NSButtonCell text label

How do I set the color of an NSButtonCell's label (title) text, that is the column cell for a table view? In my 开发者_如何转开发case, it is an checkbox button cell. (Is it possible using IB?)


Try this one,, i think its perfect one.

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];


You could try an attributed string value.

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]];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜