我正在开发一个小的 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/