Toolbar (Unified Title Bar) 工具栏(统一标题栏) macos
A row of window actions integrated with the modern macOS title bar
与现代 macOS 标题栏融为一体的一排窗口操作
标本可交互 —— 点点看。Specimen is live — try it.
Anatomy — every part, named解剖 —— 每个部件的名字
-
1 Toolbar item工具栏项
NSToolbarItemOne button, search field, control group, or flexible space in the toolbar is a toolbar item.
工具栏里的一个按钮、搜索框、控件组或弹性空白,都是一个工具栏项。
Prompt fragmentPrompt 片段a native toolbar item (NSToolbarItem): one action, field, group, or flexible space placed with standard macOS toolbar behavior
原生工具栏项(NSToolbarItem):按标准 macOS 工具栏行为放置的一个操作、输入框、控件组或弹性空白
-
2 Toolbar item label工具栏项标签
NSToolbarItem.labelThe text shown beneath an icon in icon-and-text mode is the item label; the customization palette can use a separate palette label.
图标加文字模式下显示在图标下方的文字就是项标签;自定义调板里可以用单独的调板标签。
Prompt fragmentPrompt 片段the toolbar item label (NSToolbarItem.label): the action name shown with the icon in icon-and-text display mode
工具栏项标签(NSToolbarItem.label):图标加文字显示模式下与图标一起显示的操作名称
-
3 Overflow chevron溢出箭头
NSToolbarItem.visibilityPriorityThe trailing chevron that appears when items no longer fit opens the toolbar's overflow menu.
工具栏项放不下时末尾出现的箭头,点开就是工具栏的溢出菜单。
Prompt fragmentPrompt 片段the toolbar overflow chevron (NSToolbarItem.visibilityPriority): the trailing » control that collects toolbar items that no longer fit
工具栏溢出箭头(NSToolbarItem.visibilityPriority):末尾的 » 控件,收纳放不下的工具栏项
-
4 Title-bar separator styles标题栏分隔线样式
NSWindow.titlebarSeparatorStyleThe boundary under the toolbar can be automatic, a visible line, a shadow, or absent through the title-bar separator style.
工具栏下方的边界可以通过标题栏分隔线样式设为自动、可见线条、阴影或没有。
Prompt fragmentPrompt 片段the title-bar separator style (NSWindow.titlebarSeparatorStyle): the automatic, line, shadow, or none boundary between unified toolbar chrome and window content
标题栏分隔线样式(NSWindow.titlebarSeparatorStyle):统一工具栏外框与窗口内容之间的边界,可选自动、线条、阴影或无
Prompt — paste into your agentPrompt —— 直接粘贴给你的代理
Create a Toolbar (Unified Title Bar) with NSToolbar and NSWindow.ToolbarStyle.unified (SwiftUI: View.toolbar), using native NSToolbarItem placement and spacing. Keep the title inline with the actions and let NSWindow.titlebarSeparatorStyle control the divider above the content.
用 NSToolbar 和 NSWindow.ToolbarStyle.unified(SwiftUI:View.toolbar)创建工具栏(统一标题栏),采用原生 NSToolbarItem 的布局与间距。让标题与操作保持在同一行,并用 NSWindow.titlebarSeparatorStyle 控制内容上方的分隔线。
Debug prompt — when it misbehaves调试 Prompt —— 当它不听话时
Debug my macOS toolbar (NSToolbar, NSToolbarItem). Rule out: items missing because they are absent from itemIdentifiers defaults vs alloweds; items greyed by validateToolbarItem returning false (or not implemented for custom views); user customization not persisting without autosavesConfiguration; unified title bar style shifting content layout under the toolbar. The symptom:
调试我的 macOS 工具栏(NSToolbar、NSToolbarItem)。逐一排除:工具栏项缺失,因为没加进 itemIdentifiers 的默认项或允许项;validateToolbarItem 返回 false(或自定义视图没实现它)导致项变灰;没有 autosavesConfiguration,用户的自定义无法保存;统一标题栏样式让内容布局缩到了工具栏下面。症状是:
In code代码里叫什么
| Framework框架 | Symbol符号 | Note说明 |
|---|---|---|
| AppKit | NSToolbar | |
| AppKit | NSToolbarItem | |
| AppKit | NSWindow.ToolbarStyle.unified | places the window title inline with toolbar items让窗口标题与工具栏项排在同一行 |
| AppKit | NSWindow.titlebarSeparatorStyle | |
| SwiftUI | View.toolbar(content:) |