How to make window transparent in osx swift?

给你一囗甜甜゛ 提交于 2020-01-19 17:40:09

问题


I have a empty created project in Xcode.

When I press run button, it displays a window. How can I change it's appearance like transparency of window etc.

I've searched a lot but everyone uses a window variable to change like here but how can I create NSWindow instance?

I'm new to mac app development. So can anyone write a detailed answer?

Thank you!


回答1:


You can get an instance of your application window as follow:

guard let window = NSApplication.shared().windows.first else { return }
window.isOpaque = false
window.backgroundColor = .clear

Get your window from NSApp (global constant for the shared app instance):

guard let window = NSApp.windows.first else { return }

Or override viewWillAppear or viewDidAppear and access your view's window property.

override func viewWillAppear() {
    super.viewWillAppear()
    view.window?.isOpaque = false
    view.window?.backgroundColor = .clear
}


来源:https://stackoverflow.com/questions/42754898/how-to-make-window-transparent-in-osx-swift

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