Skip to main content

类:TouchBarSegmentedControl

类:TouchBarSegmentedControl

🌐 Class: TouchBarSegmentedControl

创建一个分段控制(按钮组),其中一个按钮处于选中状态

进程: 主进程
此类未从 'electron' 模块导出。它仅作为 Electron API 中其他方法的返回值提供。

new TouchBarSegmentedControl(options)

  • options 对象
    • segmentStyle 字符串(可选)- 段落的样式:
      • automatic - 默认。分段控件的外观会根据控件所显示的窗口类型以及在窗口中的位置自动确定。映射到 NSSegmentStyleAutomatic
      • rounded - 该控件以圆角样式显示。映射到 NSSegmentStyleRounded
      • textured-rounded - 控件以带纹理的圆角样式显示。对应 NSSegmentStyleTexturedRounded
      • round-rect - 该控件以圆角矩形样式显示。映射到 NSSegmentStyleRoundRect
      • textured-square - 控件以带纹理的方形样式显示。对应 NSSegmentStyleTexturedSquare
      • capsule - 该控件以胶囊样式显示。映射到 NSSegmentStyleCapsule
      • small-square - 该控件以小方块样式显示。映射到 NSSegmentStyleSmallSquare
      • separated - 控件中的各个段显示得非常接近,但没有相互接触。映射到 NSSegmentStyleSeparated
    • mode 字符串(可选)- 控件的选择模式:
      • single - 默认。一次选择一个项目,选择一个会取消之前选择的项目。映射到 NSSegmentSwitchTrackingSelectOne
      • multiple - 可以同时选择多个项目。映射到 NSSegmentSwitchTrackingSelectAny
      • buttons - 让这些分段作为按钮,每个分段都可以按下和释放,但永远不会被标记为激活。映射到 NSSegmentSwitchTrackingMomentary
    • segments SegmentedControlSegment[] - 一个数组,用于在此控件中放置各个分段。
    • selectedIndex 整数(可选)- 当前选中段的索引,会随着用户操作自动更新。当模式为 multiple 时,它将是最后选中的项目。
    • change 函数(可选)- 当用户选择一个新段时调用。
      • selectedIndex 整数 - 用户选择的片段索引。
      • isSelected 布尔值 - 表示该片段是否因用户选择而被选中。

实例属性

🌐 Instance Properties

以下属性可在“TouchBarSegmentedControl”实例中获得:

🌐 The following properties are available on instances of TouchBarSegmentedControl:

touchBarSegmentedControl.segmentStyle

string 表示控件当前的分段样式。更新此值会立即更新触控栏中的控件。

🌐 A string representing the controls current segment style. Updating this value immediately updates the control in the touch bar.

touchBarSegmentedControl.segments

一个 SegmentedControlSegment[] 数组,表示此控件中的各个片段。更新此值会立即更新触控栏中的控件。更新此数组中的深层属性 不会更新触控栏

🌐 A SegmentedControlSegment[] array representing the segments in this control. Updating this value immediately updates the control in the touch bar. Updating deep properties inside this array does not update the touch bar.

touchBarSegmentedControl.selectedIndex

Integer 表示当前选中的段。更改此值会立即更新触控栏中的控件。用户与触控栏的交互将自动更新此值。

🌐 An Integer representing the currently selected segment. Changing this value immediately updates the control in the touch bar. User interaction with the touch bar will update this value automatically.

touchBarSegmentedControl.mode

一个 string,表示控件的当前选择模式。可以是 singlemultiplebuttons

🌐 A string representing the current selection mode of the control. Can be single, multiple or buttons.