Swift/OS X - 删除应用程序标题栏并添加自定义关闭按钮

标签 swift macos button titlebar

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

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

所有这一切只是移除灰色条,但按钮仍留在原处。

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

最佳答案

要显示/隐藏窗口按钮需要设置 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
}

因此您可能会使用类似这样的东西来设置此可见性:

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

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

关于Swift/OS X - 删除应用程序标题栏并添加自定义关闭按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34823763/

相关文章:

c - 为什么我的第一个 if 语句被跳过并且不接受 C 中的输入?

macos - 在 Mac OS X 中获取进程创建通知

objective-c - 当应用程序移至垃圾箱或应用程序在 Mac 中被删除时如何收到通知?

c# - 根据某些条件启用和禁用按钮、标签

使用 Realm 和 RAC 进行 Swift 单元测试

ios - 如何更改 SwiftUI 中 NavigationView 的背景颜色?

ios - 在 AppDelegate 类中处理 Storyboard的 View Controller

swift - 我需要检查 UIAlertAction 并避免关闭 UIAlertController

python - 覆盖 Tkinter "X"按钮控件(关闭窗口的按钮)

javascript - JQuery 调用弹出窗口