Reputation: 122
I am currently trying to change the tint of the NSVisualEffectView. This is what I got so far:
class MainViewViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
// create a colored view to tint the visual effect view
let coloredView = NSView(frame: self.view.frame)
coloredView.layer?.backgroundColor = NSColor(red: 1, green: 0, blue: 0, alpha: 0.5).cgColor
// create the visual effect view for the background blur
let visualEffectView = NSVisualEffectView(frame: self.view.frame)
visualEffectView.addSubview(coloredView)
// add the visual effect view
self.view.addSubview(visualEffectView, positioned: NSWindow.OrderingMode.below, relativeTo: nil)
}
}
As you can see I tried to add another layer that tints the visual effect view. However this didn't work.
Is there any chance I can change the color of the NSVisualEffectView?
Upvotes: 0
Views: 1236
Reputation: 1708
You don't change the color "of" a visual effect view because it has no color. The visual effect view blends the background and foreground (subviews) according to the view's material and blending mode. The "background" is either what's under the visual effect view within the window, or what's behind the window.
In these examples there's a blue NSBox within a visual effect view which is within a red NSBox.
This visual effect view's blending mode is "behind" window. Note that you see the green from behind the window as the blended background within the visual effect view.
This visual effect view's blending mode is "within" window. Note that you see the red box which is the background of the visual effect view.
In both cases the material is "light" in appearance. Different materials will have a different appearance.
There is no generic way have "blurry colored background" created by a visual effect view. It's intended to be used certain ways, based on the material/blending mode combination, and each will have different appearances.
Upvotes: 3