开发者

How do I set the color of an NSButtonCell text label

开发者 https://www.devze.com 2023-01-19 19:52 出处:网络
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 thi

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

精彩评论

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