28

The Apples Human Interface Guidelines say:

macOS Human Interface Guidelines: Panels

How do I make the very first titlebar in that image (with only a close button). Disabling both Resize and Minimize in IB only make the resize/minimize buttons get disabled. But I want them to disappear. How can I do that?

Paulo Mattos
  • 18,845
  • 10
  • 77
  • 85

4 Answers4

57

I believe this should work:

[[window standardWindowButton:NSWindowCloseButton] setHidden:YES];
[[window standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES];
[[window standardWindowButton:NSWindowZoomButton] setHidden:YES];
pkamb
  • 33,281
  • 23
  • 160
  • 191
kperryua
  • 10,524
  • 1
  • 38
  • 24
12

Swift code for accepted answer

window!.standardWindowButton(.miniaturizeButton)!.isHidden = true
window!.standardWindowButton(.zoomButton)!.isHidden = true
window!.standardWindowButton(.closeButton)!.isHidden = true
Kaunteya
  • 3,107
  • 1
  • 35
  • 66
  • is not working(on xcode 9.2)... the title and the close, miniaturizeButton, fullscreen buttons are still there. – themihai Feb 12 '18 at 08:01
2

I also needed this but visible for mouse overs - Swift:

var trackingTag: NSTrackingRectTag?
override func mouseEntered(with theEvent: NSEvent) {
    if trackingTag == theEvent.trackingNumber {
        window!.standardWindowButton(.closeButton)!.alphaValue = 1.00
    }
}
override func mouseExited(with theEvent: NSEvent) {
    if trackingTag == theEvent.trackingNumber {
        window!.standardWindowButton(.closeButton)!.alphaValue = 0.01
    }
}
func updateTrackingAreas(_ establish : Bool) {
    if let tag = trackingTag {
        window!.standardWindowButton(.closeButton)!.removeTrackingRect(tag)
    }
    if establish, let closeButton = window!.standardWindowButton(.closeButton) {
        trackingTag = closeButton.addTrackingRect(closeButton.bounds, owner: self, userData: nil, assumeInside: false)
    }
}
override func windowDidLoad() {
    window!.ignoresMouseEvents = false
    updateTrackingAreas(true)
    window!.standardWindowButton(.closeButton)!.alphaValue = 0.01
}
func windowShouldClose(_ sender: Any) -> Bool {
    window!.ignoresMouseEvents = true
    updateTrackingAreas(false)
    return true
}

Visibility is needed but just slightly - 0.01 opacity, to have the tracking area effective.

slashlos
  • 913
  • 9
  • 17
1

another way is...

for (id subview in [self window].contentView.superview.subviews) {
    if ([subview isKindOfClass:NSClassFromString(@"NSTitlebarContainerView")]) {
        NSView *titlebarView = [subview subviews][0];
        for (id button in titlebarView.subviews) {
            if ([button isKindOfClass:[NSButton class]]) {
                [button setHidden:YES];
            }
        }
    }
}
csaint
  • 21
  • 3