I need some help with figuring out how to disable/hide the close, minimize, and resize buttons in OS X Cocoa and Swift 2. Here's the code I tried. I know it's for the Title Bar, but I thought I'd try it anyway:
self.window.titleVisibility = NSWindowTitleVisibility.Hidden;
Does any one know how to do that? I'm using Swift 2, OS X Cocoa, and Xcode 7.2. Thanks!
See the NSWindow.styleMask property and the Window Style Masks.
Clearing the NSClosableWindowMask, NSMiniaturizableWindowMask, and NSResizableWindowMask flags will remove all of the buttons from a window's title bar.
window.styleMask &= ~(NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)
In Xcode 9.1 you can use following in the ViewController,
override func viewWillAppear() {
self.view.window?.titleVisibility = .hidden
self.view.window?.titlebarAppearsTransparent = true
self.view.window?.styleMask.insert(.fullSizeContentView)
self.view.window?.styleMask.remove(.closable)
self.view.window?.styleMask.remove(.fullScreen)
self.view.window?.styleMask.remove(.miniaturizable)
self.view.window?.styleMask.remove(.resizable)
//self.view.window?.isMovable = false
}
override func viewWillAppear() {
self.view.window?.titleVisibility = .hidden
self.view.window?.titlebarAppearsTransparent = true
self.view.window?.styleMask.insert(.fullSizeContentView)
//self.view.window?.styleMask.remove(.closable)
self.view.window?.styleMask.remove(.fullScreen)
self.view.window?.styleMask.remove(.miniaturizable)
self.view.window?.styleMask.remove(.resizable)
//self.view.window?.isMovable = false
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With