Skip to main content

类:TouchBarButton

类:TouchBarButton

¥Class: TouchBarButton

在触摸栏中为原生 macOS 应用创建一个按钮

¥Create a button in the touch bar for native macOS applications

进程:主进程
该类不是从 'electron' 模块导出的。它仅可用作 Electron API 中其他方法的返回值。

¥Process: Main
This class is not exported from the 'electron' module. It is only available as a return value of other methods in the Electron API.

new TouchBarButton(options)

  • options 对象

    ¥options Object

    • label 字符串(可选) - Button text.

      ¥label string (optional) - Button text.

    • accessibilityLabel 字符串(可选) - 供 VoiceOver 等屏幕阅读器使用的按钮的简短说明。

      ¥accessibilityLabel string (optional) - A short description of the button for use by screenreaders like VoiceOver.

    • backgroundColor 字符串(可选) - 十六进制格式的按钮背景颜色,即 #ABCDEF

      ¥backgroundColor string (optional) - Button background color in hex format, i.e #ABCDEF.

    • icon NativeImage | 字符串(可选) - Button icon.

      ¥icon NativeImage | string (optional) - Button icon.

    • iconPosition 字符串(可选) - 可以是 leftrightoverlay。默认为 overlay

      ¥iconPosition string (optional) - Can be left, right or overlay. Defaults to overlay.

    • click 功能(可选) - 单击按钮时调用的函数。

      ¥click Function (optional) - Function to call when the button is clicked.

    • enabled 布尔值(可选) - 按钮是否处于启用状态。默认为 true

      ¥enabled boolean (optional) - Whether the button is in an enabled state. Default is true.

定义 accessibilityLabel 时,请确保你已考虑 macOS 最佳实践

¥When defining accessibilityLabel, ensure you have considered macOS best practices.

实例属性

¥Instance Properties

以下属性在 TouchBarButton 的实例上可用:

¥The following properties are available on instances of TouchBarButton:

touchBarButton.accessibilityLabel

string 代表屏幕阅读器要读取的按钮的描述。如果未设置标签,则仅由屏幕阅读器读取。

¥A string representing the description of the button to be read by a screen reader. Will only be read by screen readers if no label is set.

touchBarButton.label

代表按钮当前文本的 string。更改此值会立即更新触摸栏中的按钮。

¥A string representing the button's current text. Changing this value immediately updates the button in the touch bar.

touchBarButton.backgroundColor

代表按钮当前背景颜色的 string 十六进制代码。更改此值会立即更新触摸栏中的按钮。

¥A string hex code representing the button's current background color. Changing this value immediately updates the button in the touch bar.

touchBarButton.icon

NativeImage 代表按钮的当前图标。更改此值会立即更新触摸栏中的按钮。

¥A NativeImage representing the button's current icon. Changing this value immediately updates the button in the touch bar.

touchBarButton.iconPosition

A string - 可以是 leftrightoverlay。默认为 overlay

¥A string - Can be left, right or overlay. Defaults to overlay.

touchBarButton.enabled

boolean 代表按钮是否处于启用状态。

¥A boolean representing whether the button is in an enabled state.