How to add buttons when NSVisualEffectView is used

蹲街弑〆低调 提交于 2019-12-05 20:07:01

I think I should have corrected you in your previous question only but I didn't.

You are using Storyboard so why are you creating NSVisualViewEffect variable in your code?

Search for nsvisualeffectview in the right panel(Utilities panel) where you search for buttons etc. (object library).

Drag it and resize it according to your main view controller.

To add the blur effect and mode, go to "Attribites Inspector" in the "Utilities panel"

and set window.backgroundColor = .clear and window.isOpaque = false

func applicationDidFinishLaunching(_ aNotification: Notification) {
        // Insert code here to initialize your application
        guard let window = NSApplication.shared.windows.first else { return }
        window.isOpaque = false
        window.backgroundColor = .clear
}

Now you can add your buttons, text fields and run the project. You can see all your added elements.

I hope it helps!

window is above the view you are adding buttons to, so the buttons are below the blurred-out window, and are therefore impossible to see. Why not add the visualEffectView to the same view as the buttons? You'd need to insert it below the buttons to make the buttons visible.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!