gpt4 book ai didi

swift - 当 isEnabled 为 false(禁用)时避免使 NSButton 透明/透明

转载 作者:搜寻专家 更新时间:2023-11-01 05:35:18 30 4
gpt4 key购买 nike

一个常规的 NSButton 如果被禁用,它似乎是透明的。

enter image description here

图像显示了一个样式为“push”的按钮

但是,我想禁用没有透明度的按钮。

我试图以编程方式将 alphaValue 设置为 1.0 但似乎 NSButtons cell (controlView) 以及所有其他 subview 的 alphaValue 已经是 1.0。

此外,没有像 userInteractionEnabledadjustsImageWhenDisabled(都推荐 here )这样的东西,我可以像在 iOS 中一样使用。

如何在没有标准透明度的情况下禁用 NSButton?

编辑:还有一个“纹理推送”按钮看起来是透明的: enter image description here

最佳答案

如果您不需要标题,并且将提供您自己的按钮图像,您可以使用 setImageDimsWhenDisabled 来禁用 NSButtonCell 禁用时图像的透明度.这是代码:

[buttonCell setImageDimsWhenDisabled:NO];

NSButtonCellNSButton 的 subview 。但正如我所说,标题仍然会“变暗”一点,它的背景也是如此。但由于图像位于背景之上,您将看不到透明背景。

另一种方法(避免子类 NSButton)是为按钮设置自己的状态跟踪变量。当状态为禁用时,取消任何点击事件。示例代码框架如下:

- (IBAction)clickOnButton {
static BOOL isEnabled = YES;
if (isEnabled) {
// Handle click event here...

}
isEnabled = !isEnabled;
}

这可能会在单击时显示突出显示。您也可以禁用突出显示。但如果你有很多按钮,这不是一个好主意。如果你有很多按钮,子类 NSButton 是最好的选择。

关于swift - 当 isEnabled 为 false(禁用)时避免使 NSButton 透明/透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42039521/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com