Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift/OS X - Remove Application Title Bar and Add Custom Close Button

I'm working on a little mac app where I want a pretty specific style for the window. I want to remove the application's menu bar completely, and then go about adding a custom close button. (Just a little white 'X' with no borders.) The reason I want this is I'm looking to make the application's background image cover the entire window, not just the view controller area and a gray title bar splotched above. So far, my window controller contains this:

self.window!.titleVisibility = NSWindowTitleVisibility.Hidden;
self.window!.titlebarAppearsTransparent = true
self.window!.movableByWindowBackground  = true

All this does is remove the gray bar, but the buttons are left just where they were.

Thanks for reading, all help is appreciated.

like image 211
Carl Litchman Avatar asked Jan 16 '16 05:01

Carl Litchman


1 Answers

To show/hide window buttons would want to set the visibility of NSWindowButton:

These constants provide a way to access standard title bar buttons:

enum NSWindowButton : UInt {
    case CloseButton
    case MiniaturizeButton
    case ZoomButton
    case ToolbarButton
    case DocumentIconButton
    case DocumentVersionsButton
    case FullScreenButton
}

So you would likely use something such as this to set this visibility:

self.window!.standardWindowButton(NSWindowButton.CloseButton)?.hidden = true

Any other constants you want to prevail would likely work the same way. You would then set your new custom close button for example to the applications first responder terminate function.

like image 189
l'L'l Avatar answered Oct 17 '22 00:10

l'L'l