NSCell 上的 NSAttributedString
我正在使用 NSAttributedString 格式化的数据填充 NSOutlineView。到目前为止,我已经设置了文本字体、大小和颜色的格式。我的问题是,选择行时前景色不会改变。如果您创建 NSTextFieldCell 并在界面生成器上将颜色设置为disabledControlTextColor,则它可以正常工作:未选择时,它显示为灰色,选择白色时,当我以编程方式将此颜色设置为属性字符串定义时,它始终显示为灰色的。
NSMutableAttributedString *result = [[[NSMutableAttributedString alloc] initWithString:value] autorelease];
NSDictionary *attributes = [[NSDictionary dictionaryWithObjectsAndKeys:
[NSFont systemFontOfSize:[NSFont systemFontSize] -1], NSFontAttributeName,
[NSColor disabledControlTextColor], NSForegroundColorAttributeName, nil] retain];
[result addAttributes:attributes range:[value rangeOfString:value]];
提前致谢。
I'm filling an NSOutlineView with data that I format using NSAttributedString. So far I have formatted the text font, size and color. My problem is that the foreground color doesn't change when the row is selected. If you create an NSTextFieldCell and set the color to disabledControlTextColor on the Interface Builder, it works fine: When not selected it is show as gray, and when selected white, when I programmatically set this color to the attributed string definition it is always show as gray.
NSMutableAttributedString *result = [[[NSMutableAttributedString alloc] initWithString:value] autorelease];
NSDictionary *attributes = [[NSDictionary dictionaryWithObjectsAndKeys:
[NSFont systemFontOfSize:[NSFont systemFontSize] -1], NSFontAttributeName,
[NSColor disabledControlTextColor], NSForegroundColorAttributeName, nil] retain];
[result addAttributes:attributes range:[value rangeOfString:value]];
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当子类化 NSCell 时,在设置文本字段值时,我们应该询问该单元格是否突出显示,然后设置文本的前景色。
When subclassing NSCell, when setting the textfield value, we should ask if the cell isHighlighted and then set the foreground color of the text.
在自定义单元格中使用它,我尝试了互联网上的所有内容,最后下面的东西起作用了
use this in the custom cell, i tried everything on the internet and finally below thing worked