【问题标题】:Swift/OS X - Remove Application Title Bar and Add Custom Close ButtonSwift/OS X - 删除应用程序标题栏并添加自定义关闭按钮
【发布时间】:2016-04-21 19:06:39
【问题描述】:

我正在开发一个小的 Mac 应用程序,我想要一个非常具体的窗口样式。我想完全删除应用程序的菜单栏,然后​​添加自定义关闭按钮。 (只是一个没有边框的白色“X”。)我想要这个的原因是我想让应用程序的背景图像覆盖整个窗口,而不仅仅是视图控制器区域和上面的灰色标题栏。到目前为止,我的窗口控制器包含以下内容:

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

所有这一切都是删除灰色条,但按钮留在原来的位置。

感谢阅读,感谢所有帮助。

【问题讨论】:

    标签: swift macos button titlebar


    【解决方案1】:

    要显示/隐藏窗口按钮想设置NSWindowButton的可见性:

    这些常量提供了一种访问标准标题栏按钮的方法:

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

    所以你可能会使用这样的东西来设置这个可见性:

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

    您想要占优势的任何其他常量都可能以相同的方式工作。然后,您可以将新的自定义关闭按钮设置为应用程序第一响应者 terminate 函数。

    【讨论】:

    • 我一回到家就试一试 - 如果它有效,我会标记它是正确的。 :)
    猜你喜欢
    • 1970-01-01
    • 2019-04-15
    • 1970-01-01
    • 2011-09-04
    • 1970-01-01
    • 1970-01-01
    • 2020-08-11
    • 1970-01-01
    • 2010-10-25
    相关资源
    最近更新 更多