Skip to main content

Class: TouchBarButton

Class: TouchBarButton

Create a button in the touch bar for native macOS applications在触摸条中为本机macOS应用程序创建一个按钮

Process:进程:Main
This class is not exported from the 'electron' module. 此类不是从'electron'模块导出的。It is only available as a return value of other methods in the Electron API.它只能作为Electron API中其他方法的返回值使用。

new TouchBarButton(options)

  • options Object
    • label string (optional) - Button text.按钮文本。
    • accessibilityLabel string (optional) - A short description of the button for use by screenreaders like VoiceOver.按钮的简短说明,供VoiceOver等屏幕阅读器使用。
    • backgroundColor string (optional) - Button background color in hex format, i.e #ABCDEF.十六进制格式的按钮背景色,即#ABCDEF
    • icon NativeImage | string (optional) - Button icon.按钮图标。
    • iconPosition string (optional) - Can be left, right or overlay. 可以是leftrightoverlayDefaults to overlay.默认为overlay
    • click Function (optional) - Function to call when the button is clicked.单击按钮时要调用的函数。
    • enabled boolean (optional) - Whether the button is in an enabled state. 按钮是否处于启用状态。Default is true.默认值为true

When defining accessibilityLabel, ensure you have considered macOS best practices.在定义accessibilityLabel时,请确保您考虑了macOS的最佳实践

Instance Properties实例属性

The following properties are available on instances of TouchBarButton:TouchBarButton实例上提供了以下属性:

touchBarButton.accessibilityLabel

A string representing the description of the button to be read by a screen reader. 一个string,表示屏幕阅读器要读取的按钮的描述。Will only be read by screen readers if no label is set.只有在未设置标签的情况下,才会由屏幕阅读器读取。

touchBarButton.label

A string representing the button's current text. 表示按钮当前文本的stringChanging this value immediately updates the button in the touch bar.更改此值会立即更新触摸栏中的按钮。

touchBarButton.backgroundColor

A string hex code representing the button's current background color. 一个string表示按钮当前背景颜色的十六进制代码。Changing this value immediately updates the button in the touch bar.更改此值会立即更新触摸栏中的按钮。

touchBarButton.icon

A NativeImage representing the button's current icon. 表示按钮当前图标的NativeImageChanging this value immediately updates the button in the touch bar.更改此值会立即更新触摸栏中的按钮。

touchBarButton.iconPosition

A string - Can be left, right or overlay. 一个string-可以是leftrightoverlayDefaults to overlay.默认为overlay

touchBarButton.enabled

A boolean representing whether the button is in an enabled state.一个boolean,表示按钮是否处于启用状态。