在 titlebar/toolbar 的左侧添加 NSTitlebarAccessoryViewController

Add NSTitlebarAccessoryViewController to the left of the titlebar/toolbar

我已经实现了统一 titlebar/toolbar,现在想在栏中添加两个按钮。它们需要位于红绿灯按钮的最左侧和右侧。我正在创建一个与系统偏好设置非常相似的工具栏。

我查看了用于添加 NSTitlebarAccessoryViewController 的 API,layoutAttribute 的唯一有效属性是 NSLayoutAttributeRight(将视图添加到工具栏的最右侧) 和 NSLayoutAttributeBottom 本质上是将视图放在其自己的工具栏中的统一工具栏下方。

这两个选项我都不想要,那么如何在统一工具栏的最左侧添加一堆按钮呢?

实际上归档这个要容易得多:

只需使用 Interface Builder 将工具栏添加到 window 并将标题可见性设置为隐藏即可:

[window setTitleVisibility:NSWindowTitleHidden];

您可以使用 WAYAppStoreWindow on GitHub to do this. I created a fork of the WAYWindow 子项目使文档标题垂直居中,因为这不受支持。

现在可以在 OS X 10.11 中实现。引用自头文件:

For applications linked on Mac OS 10.11 or later, NSLayoutAttributeLeft is also supported; placing the item on the left side of the window (adjacent and to the right of the close/minimize/maximize buttons).