Last active
March 27, 2021 23:42
-
-
Save PierBover/e4ab422e984f4170c152be058a920bb3 to your computer and use it in GitHub Desktop.
How to add a NSVisualEffectView to a View in Cocoa
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Cocoa | |
class MyViewController: NSViewController { | |
var visualEffect: NSVisualEffectView! | |
override func loadView() { | |
super.loadView() | |
visualEffect = NSVisualEffectView() | |
visualEffect.translatesAutoresizingMaskIntoConstraints = false | |
visualEffect.material = .dark | |
visualEffect.state = .active | |
view.addSubview(visualEffect) | |
visualEffect.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true | |
visualEffect.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true | |
visualEffect.topAnchor.constraint(equalTo: view.topAnchor).isActive = true | |
visualEffect.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment