首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何设置NSButtonCell文本标签的颜色

如何设置NSButtonCell文本标签的颜色
EN

Stack Overflow用户
提问于 2010-10-14 19:53:49
回答 2查看 10.2K关注 0票数 6

如何设置NSButtonCell的标签(标题)文本的颜色,即表格视图的列单元格?在我的例子中,它是复选框按钮单元格。(是否可以使用IB?)

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-01-01 20:33:34

试试这个吧,我觉得它很完美。

代码语言:javascript
复制
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];
票数 14
EN

Stack Overflow用户

发布于 2010-10-14 22:37:21

你可以尝试一个属性字符串值。

代码语言:javascript
复制
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]];
票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3932796

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档