Disable NSTextField without changing color of multi-colored text

拈花ヽ惹草 提交于 2019-12-12 01:33:02

问题


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.


回答1:


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



回答2:


I discovered that while I was editing the text I could set colors and everything, but the problem of the text losing color was happening even when I didn't disable the text box. I had neglected to allow my NSTextField to allow rich text. Now the textfield keeps all colors even when I setEditable:NO.



来源:https://stackoverflow.com/questions/23430007/disable-nstextfield-without-changing-color-of-multi-colored-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!