How to put a label on a vibrant window

How can I put a simple label in a window with a vibrant background (similar to a semi-transparent window)


I can make the window vibrant with that code:


override func viewWillAppear() {
super.viewWillAppear()

  let visualEffect = NSVisualEffectView()
  visualEffect.blendingMode = .behindWindow
  visualEffect.state = .active
  visualEffect.material = .light
  view.window?.contentView = visualEffect
}


But If I put a simple label with any text in the storyboard, the label is not visible. If I remove the code of the vibrant background the label appear again. Perhaps I should put the label in another layer? if so, how?

Accepted Reply

That's because you get rid of the view which holds the subviews as label.


One way to achieve, in IB:

- drop a NSVisualEffectView in the ViewController

- size it to the full size and set its properties in attributes inspector

- move all objects of the initial view (as label) inside this view

- remove the former view

Replies

That's because you get rid of the view which holds the subviews as label.


One way to achieve, in IB:

- drop a NSVisualEffectView in the ViewController

- size it to the full size and set its properties in attributes inspector

- move all objects of the initial view (as label) inside this view

- remove the former view

Thank you!


"- remove the former view"


I could make the View transparent:

view.window?.isOpaque = false

view.window?.backgroundColor = NSColor.clear


But is it possible to totally remove it? how?

Exact, cannot and should not remove, just make it transparent.


Either:

        self.view.window?.isOpaque = false

or

        self.view.window?.backgroundColor = .clear


or both:


    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        self.view.window?.isOpaque = false
        self.view.window?.backgroundColor = .clear
    }