Search code examples
swiftmacosnsbutton

Disable NSButton without grayed image


I want to disable the user interaction of NSButton. The only possible option seems to be setting isEnabled to false:

button.isEnabled = false

...but the problem is that it's giving a white shade to the image of my button. Is there any way to get rid of that shade?


Solution

  • You have to set the imageDimsWhenDisabled property of the corresponding button cell:

    button.isEnabled = false
    if let cell = button.cell as? NSButtonCell {
        cell.imageDimsWhenDisabled = false
    }