禁用NSTextField而不更改多色文本的颜色 [英] Disable NSTextField without changing color of multi-colored text
本文介绍了禁用NSTextField而不更改多色文本的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
每当我禁用NSTextField时,文本就会失去颜色并变为灰色.如何禁用文本字段并保持文本颜色?在我的特定情况下,某些单词会被涂成红色.禁用时,我希望这些词保持红色.
Whenever I disable an NSTextField the text loses its color and changes to gray. How can I disable the text field and keep the text color? In my particular situation some words are colored red. I'd like those words to stay red when I disable.
推荐答案
您需要将NSTextField
子类化.参见 CocoaBuilder线程:
You need to subclass NSTextField
to do that. See this CocoaBuilder thread:
- (void)setEnabled:(BOOL)flag
{
[super setEnabled:flag];
if (!flag) {
[self setTextColor:[NSColor secondarySelectedControlColor]];
} else {
[self setTextColor:[NSColor controlTextColor]];
}
}
这篇关于禁用NSTextField而不更改多色文本的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文