25

苹果人机界面指南说:

macOS 人机界面指南:面板

如何制作该图像中的第一个标题栏(只有一个关闭按钮)。在 IB 中同时禁用ResizeMinimize只会使 resize/minimize 按钮被禁用。但我希望它们消失。我怎样才能做到这一点?

4

4 回答 4

54

我相信这应该有效:

[[window standardWindowButton:NSWindowCloseButton] setHidden:YES];
[[window standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES];
[[window standardWindowButton:NSWindowZoomButton] setHidden:YES];
于 2009-08-24T14:12:04.073 回答
12

接受答案的 Swift 代码

window!.standardWindowButton(.miniaturizeButton)!.isHidden = true
window!.standardWindowButton(.zoomButton)!.isHidden = true
window!.standardWindowButton(.closeButton)!.isHidden = true
于 2017-04-12T13:12:20.877 回答
2

我也需要这个,但对于鼠标悬停可见 - 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
}

需要可见性,但需要一点点 - 0.01 不透明度,以使跟踪区域有效。

于 2018-03-22T21:23:18.450 回答
1

另一种方法是...

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];
            }
        }
    }
}
于 2015-12-18T02:43:10.270 回答