问题
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