6

I have a NSVisualEffectView within a NSPopover developed for 10.10.

When subclassing the NSVisualEffectView to have hover background color effect, the borderless button color seems to be different

gray box

I tried setting the backgroundColor of the button cell to clearColor or the same as I used in drawRect: in of the NSVisualEffectView, the former gives wrong color (not filled with blue) and the later still the same with wrong color. (gray box around its border).

CALayer can fix this but is there a way without using it?

Any ideas?

carbonr
  • 6,049
  • 5
  • 46
  • 73
Cai
  • 3,609
  • 2
  • 19
  • 39

2 Answers2

3

After much trial and error, this worked for me:

button.wantsLayer = true
button.layer?.backgroundColor = NSColor.clearColor().CGColor

I've got an NSTableView with NSVisualEffectView style. I created a custom NSTableViewCell class and put these lines in its drawRect method.

  • As I no longer have a working project to verify this (thanks to the syntax changes made in Swift 2), I'll give you an upvote for your effort. I assume this will work as, after a year more in being a developer, seems most drawing issues can be solved by utilizing the CA layer (`.wantsLayer`). However, since this is SO, until someone can confirm it, I can't mark this as an answer. – Cai Apr 06 '16 at 00:54
  • I happened to have another project that came across this issue. Seems that this will not always fix the problem, e.g. place a button on a NSImageView. Still looking for solutions once for all. – Cai May 31 '16 at 01:41
  • 1
    I tried this, even `CGColor.clear`, and it has no effect – Ky - Dec 09 '16 at 20:21
  • I added a image to the button there is a way to make it with vibrancy effect? – Avi Rok Aug 17 '21 at 22:42
0

This has been open for a long time but I just needed the answer myself and maybe someone else is happy to find this here, answer works only for Mac OS 10.14 and up

button.contentTintColor = .white

By setting the contetTintColor to whatever you might need it will for some reason remove the background color.

Sphere
  • 11
  • 1