Xcode & Swift - Window Without Title Bar But with Close, Minimize and Resize Buttons

Xcode & Swift - Window without title bar but with close, minimize and resize buttons


If you are using storyboard, it's just a simple check box in the Inspector bar.

  1. Select the window from Story Board
    Sample Image

  2. Check the Transparent Title Bar checkbox in the inspector window.

Sample Image

Here's how it looks like in the Story board. It looks the same when you build and run the application.

Sample Image

How to present NSWindow without title bar while keeping the system buttons

I figured out how to achieve the desired design:

  • In the storyboard, set NSWindow's Full Size Content View property to true
  • Via code, set NSWindow's titlebarAppearsTransparent property to true

How to make an application with a window without decorators (no close, minimize, maximize buttons as well as no border)

Yes, you can create windows with no decorations, in the interface builder portion of Xcode just uncheck Close, Minimize, Resize and Title Bar. This will leave you with a window that has no decorations but still has a drop shadow.

With this type of setup, however, you will not have any window controls, and if you add custom buttons to close the window they will not link up with your menu items for close, zoom or minimize.

Also, you will probably want to set the movableByWindowBackground property of your window to YES, otherwise the user will not be able to move it.

If you wish to have a custom window design (custom close, zoom, minimize buttons) with the ability to customize the titlebar, I would highly reccommend INAppStoreWindow[1] for the task. I am using it in my project to great effect!

[1]https://github.com/indragiek/INAppStoreWindow

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

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.

NSWindow Titlebar with close button

You can enable/disable Window buttons through IB but you cannot hide or remove them completely from window through IB alone. You would need get the button reference and hide it. Somewhat like this :

NSButton *closeButton = [self.window standardWindowButton:NSWindowCloseButton];
[closeButton setHidden:YES];

How to show title bar

You need to add .titled to the window's styleMask.

view.window?.styleMask.insert(.titled)

How can I disable the close button?

Also try;

    self.window!.standardWindowButton(NSWindow.ButtonType.closeButton)!.hidden = true
self.window!.standardWindowButton(NSWindow.ButtonType.miniaturizeButton)!.hidden = true

etc.

Hide buttons from titlebar in Cocoa

I believe this should work:

[[window standardWindowButton:NSWindowCloseButton] setHidden:YES];
[[window standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES];
[[window standardWindowButton:NSWindowZoomButton] setHidden:YES];


Related Topics



Leave a reply



Submit