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.
Select the window from Story Board
Check the Transparent Title Bar checkbox in the inspector window.
Here's how it looks like in the Story board. It looks the same when you build and run the application.
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 totrue
- Via code, set NSWindow's
titlebarAppearsTransparent
property totrue
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
Why Does Int(Float(Int.Max)) Give Me an Error
Iphonex Not Call Prefersstatusbarhidden
How Are Int and String Accepted as Anyhashable
Why Do Integers Not Conform to the Anyobject Protocol
Print the Nstableview's Row Number of the Row Clicked by the User
Redeclaring Members in an Extension Hides the Original Member *Sometimes*. Why
How to Increase (Animate) the Width of the Square on Both Ends
Disable Scrolling in Swiftui List/Form
How to Deallocate Realitykit Arview()
Swift 2.0 'Inout' Function Parameters and Computed Properties
How to Make Cells Have a Gradient Background
How to Embed Third Party Framework on Ionic Capacitor Custom Plugin
How to Generate Random Numbers Without Repetition in Swift