Reputation: 273
After update to Xcode 8 with Swift 3, the following code no longer work
self.view.window?.styleMask = NSTitledWindowMask | NSMiniaturizableWindowMask
Please advise me on how can I fix it?
Upvotes: 4
Views: 5044
Reputation: 273
In case anyone also having the same issue like I did, here are the working version for SWIFT 3
If using NSViewController, add the following: (Thanks to João Oliveira contribution)
override func viewDidAppear() {
self.view.window?.styleMask.insert(.titled) /* Enable Title */
self.view.window?.styleMask.insert(.closable) /* Enable Close button */
}
If using NSWindowController, add the following:
init(){
self.m_window = NSWindow(
contentRect: NSRect(300, 300, width: 500, height: 500),
styleMask: NSWindowStyleMask(rawValue: (NSWindowStyleMask.closable.rawValue | NSWindowStyleMask.titled.rawValue)),
backing: NSBackingStoreType.buffered, defer: false
)
}
** Change the X, Y position and Width and Height to your preferred window size.
Upvotes: 1
Reputation: 452
window.styleMask.insert(.fullSizeContentView)
Or
window.styleMask = window.styleMask.union(.fullSizeContentView)
Example:
override func windowDidLoad() {
super.windowDidLoad()
guard let window = window else { return }
window.titlebarAppearsTransparent = true
window.titleVisibility = .hidden
window.styleMask.insert(.fullSizeContentView)
}
Upvotes: 13