Pop-Up Button vs. Pull-Down Button vs. Combo Box 弹出式按钮 vs. 下拉式按钮 vs. 组合框 macos

pop-up button
pull-down button
combo box

标本可交互 —— 点点看。Specimen is live — try it.

Anatomy — every part, named解剖 —— 每个部件的名字

  1. 1 Current-value label当前值标签 NSPopUpButton.titleOfSelectedItem

    “The dropdown text that shows what is selected” is the pop-up button's current-value label.

    “下拉框上显示当前选中内容的文字”就是弹出式按钮的当前值标签。

    Prompt fragmentPrompt 片段

    the NSPopUpButton.titleOfSelectedItem current-value label visible while the selection control is closed

    选择控件关闭状态下显示的 NSPopUpButton.titleOfSelectedItem 当前值标签

  2. 2 Pull-down indicator下拉指示箭头 NSPopUpButton.pullsDown

    “The little arrow showing that this button opens actions” is the pull-down indicator.

    “表示这个按钮会弹出操作的小箭头”就是下拉指示箭头。

    Prompt fragmentPrompt 片段

    the menu indicator on an NSPopUpButton with pullsDown = true, signaling that the fixed-label button opens commands

    pullsDown = true 的 NSPopUpButton 上的菜单指示箭头,表明这个标签固定的按钮弹出的是命令

  3. 3 Editable value field可编辑值输入框 NSComboBox

    “The dropdown field where I can type my own value” is the combo box's editable field.

    “下拉框里能自己输入值的框”就是组合框的可编辑输入框。

    Prompt fragmentPrompt 片段

    the editable NSComboBox value field, visually joined to its suggestions-list disclosure button

    NSComboBox 的可编辑值输入框,视觉上与建议列表的展开按钮连为一体

  4. 4 Selected-item checkmark选中项勾号 NSMenuItem.state

    “The checkmark next to the current choice” is the selected menu item's state mark.

    “当前选项旁边的勾号”就是选中菜单项的状态标记。

    Prompt fragmentPrompt 片段

    the NSMenuItem.state checkmark beside the current value in an open NSPopUpButton menu

    打开的 NSPopUpButton 菜单中当前值旁边的 NSMenuItem.state 勾号

Prompt — paste into your agentPrompt —— 直接粘贴给你的代理

Choose the correct control from Pop-Up Button vs. Pull-Down Button vs. Combo Box: use NSPopUpButton with pullsDown false for a persistent selection, the same control with pullsDown true for a menu of commands, or NSComboBox when the user may type a value as well as choose one. Preserve the native arrow, menu behavior, and displayed-value semantics of the chosen control.

在弹出式按钮、下拉式按钮、组合框三者中选择正确的控件:表示持续选中状态用 pullsDown 为 false 的 NSPopUpButton;弹出命令菜单用 pullsDown 为 true 的同一个控件;需要用户既能输入又能选择时用 NSComboBox。保留所选控件的原生箭头、菜单行为和显示值语义。

Debug prompt — when it misbehaves调试 Prompt —— 当它不听话时

Debug my macOS popup/pull-down/combo (NSPopUpButton, NSComboBox). Rule out: a pull-down consuming its FIRST menu item as the title — insert a dummy first item; popup selection not syncing because selectItem was never called after menu rebuild; autoenablesItems greying items whose actions lack targets; expecting a combo box to be a menu — it is an editable text field plus a list. The symptom:

调试我的 macOS 弹出/下拉/组合框(NSPopUpButton、NSComboBox)。逐一排除:下拉式按钮把第一个菜单项吞掉当成了标题——插入一个占位的首项;菜单重建后没调用 selectItem 导致选中状态不同步;autoenablesItems 把没有目标的菜单项变灰;把组合框当成菜单用——它其实是可编辑文本框加列表。症状是:

In code代码里叫什么

Framework框架Symbol符号Note说明
AppKit NSPopUpButton a selection control when pullsDown is falsepullsDown 为 false 时是选择控件
AppKit NSComboBox an editable text field paired with a choices list可编辑文本框搭配选项列表
AppKit NSPopUpButton.pullsDown true makes it an action-oriented pull-down button设为 true 就变成面向操作的下拉式按钮
SwiftUI Picker

See also相关词条