Skip to main content

类:TouchBarButton

类:TouchBarButton​

🌐 Class: TouchBarButton

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

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

new TouchBarButton(options)​

  • options 对象
    • label string(optional)- 按钮文本。
    • accessibilityLabel string(optional)- 用于屏幕阅读器(如 VoiceOver)的按钮简短描述。
    • backgroundColor string(optional)- 按钮背景颜色的十六进制格式,例如 #ABCDEF。
    • icon NativeImage | string(optional)- 按钮图标。
    • iconPosition string(optional)- 可以是 left、right 或 overlay。默认值为 overlay。
    • click Function(optional)- 按钮被点击时调用的函数。
    • enabled boolean(optional)- 按钮是否处于启用状态。默认值为 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 - 可以是 left、right 或 overlay。默认是 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.