Disable NSButton without frame NSVisualEffectView

I have an NSVisualEffectView with brightness containing text fields (NSTextField or NSComboBox) and borderless buttons. The buttons are located above the text fields, and I want to turn off the vibration effect on the borderless buttons, because they should appear on the white background of the text fields.

What I tried to do as recommended in the reference of the NSVisualEffectView class is to wrap my NSButton inside another NSVisualEffectView with its state set to Inactive. This means that it replaces the โ€œbrightโ€ background with a light gray background.

The figure below shows this. The first field is my attempted solution, the second shows the default behavior of a borderless button as a child of NSVisualEffectView.

enter image description here

I also tried to subclass NSButton and set the cell background color to white or clear, but always get a gray background.

How to change a light gray background to white or a clean background? Thanks

+5
source share
1 answer

I managed to solve it myself after several hours of headache. The solution does not need a button that needs to be wrapped in NSVisualEffectView. Just subclassing NSButton and overriding the allowsVibrancy property and setting it to false was enough.

In Swift:

 override var allowsVibrancy: Bool { return false } 
+3
source

Source: https://habr.com/ru/post/1234977/


All Articles