不要在按下或禁用时更改NSButton外观 [英] Don't change NSButton appearance when pressed or disabled

查看:642
本文介绍了不要在按下或禁用时更改NSButton外观的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个NSButtons的图像为其开启状态和关闭状态。每次只有一个活动;单击一个,然后单击另一个更改属性来回。

I have two NSButtons with images for both their on states and off states. Only one should be active at a time; click one and then click the other to change a property back and forth.

问题是,如果我单击时禁用按钮,因此无法再次单击,当按钮被禁用时图像变暗 - 并且我不希望它变暗,我只想使用替代图像。
另一方面,如果我只是让按钮启用,但在编程方式只是没有运行任何代码,当它被点击,然后有一个闪烁的效果,鼠标点击 - 这是分心,当按钮应该不要做任何事情。

The problem is that if I disable a button when it's clicked so it cannot be clicked again, then the image is dimmed when the button is disabled--and I don't want it dimmed, I just want to use the alternate image. On the other hand, if I just leave the button enabled, but programmatically just don't run any code when it is clicked, then there's a flashing effect as the mouse clicks--which is distracting, when the button should not do anything.

所以我需要防止按钮在被禁用时变暗,或者防止它在按住鼠标按钮时改变按钮外观。

So I either need to prevent the button from being dimmed when it is disabled, or prevent it from changing the button appearance while the mouse button is held down.

阅读之后,它听起来像我需要子类NSButtonCell和覆盖 - (BOOL)imageDimsWhenDisabled做前者。但我不能弄清楚如何子类化它(我应该继承什么样的NSButtonCell类),如果NSButton的setCell方法足以使用新的NSButtonCell类,或者如果我需要子类NSButton 。

After reading up, it sounds like I need to subclass NSButtonCell and override - (BOOL)imageDimsWhenDisabled to do the former. But I can't figure out exactly how to subclass it (what sort of NSButtonCell class I should inherit from) and if the "setCell" method of NSButton is enough to use the new NSButtonCell class, or if I need to subclass NSButton as well.

有些提示会被欣赏,或者有一个完全不同的方法来实现我的目标。

Some tips on that would be appreciated, or perhaps there's a completely different approach that would achieve my objectives.

推荐答案

查看:

[btnInfo.cell setImageDimsWhenDisabled:NO];

这篇关于不要在按下或禁用时更改NSButton外观的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆