3

I am working on a Swift 4 macOS Application that involves a vibrant dark window and an in-window NSVisualEffectView. Currently, the NSVisualEffectView's color does not quite match that of the window, but it is very close.

How can I make the NSVisualEffectView's color perfectly match the window? My goal is to have the blur effect it provides only appear when content is beneath it, and making it's color match that of the window would create this effect. I have included an image of what is currently happening. You may need to zoom into the image and turn up your display brightness to see the difference. Though it appears minor in this screenshot, the NSVisualEffectView spans the entire window, and on the Retina display of a Mac, the difference is apparent.

I have tried setting the NSVisualEffectView's background color to clear, but that has not worked.

visualEffectView.wantsLayer = true
visualEffectView.layer?.backgroundColor = NSColor.clear.cgColor

I would appreciate any advice on this!

enter image description here

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Jake3231
  • 703
  • 8
  • 22
  • 1) Not sure, what you are asking: if your effects view spans the whole window, which parts don't match up? 2) to influence the colors: have you tried adding a helper view above the effects view and filling that view with a transparent color? – mschmidt Dec 04 '17 at 23:44
  • The color of the NSVisualEffectView and that of the vibrant dark window do not match, and I would like them to be exactly the same. The idea is that you cannot see the effect view, but when content is beneath it the blur still works. Can you clarify on what sort of helper view I would use? – Jake3231 Dec 04 '17 at 23:54
  • Add an additional subview to the effects view (full size and located below other content). Fill the layer of this subview with a transparent, dark color. The effects view then gets some kind of color tint. You have to play with the color and transparency. – mschmidt Dec 05 '17 at 08:17
  • Can be done, see: https://stackoverflow.com/questions/23821693/cocoa-nsview-blurred-background/39193996 – Sentry.co May 13 '21 at 15:56

0 Answers0