跳转到主要内容

类:TouchBarButton

类:TouchBarButton

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

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

new TouchBarButton(options)

  • options Object
    • label 字符串(可选)- 按钮文本。
    • accessibilityLabel 字符串(可选)- 屏幕阅读器(如 VoiceOver)使用的按钮简短描述。
    • backgroundColor 字符串(可选)- 按钮背景色,十六进制格式,例如 #ABCDEF
    • icon NativeImage | 字符串(可选)- 按钮图标。
    • iconPosition 字符串(可选)- 可以是 leftrightoverlay。默认为 overlay
    • click 函数(可选)- 点击按钮时调用的函数。
    • enabled 布尔值(可选)- 按钮是否处于启用状态。默认为 true

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

实例属性

TouchBarButton 实例可用的属性如下:

touchBarButton.accessibilityLabel

一个 string,表示屏幕阅读器将读取的按钮描述。仅当未设置标签时,屏幕阅读器才会读取此描述。

touchBarButton.label

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

touchBarButton.backgroundColor

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

touchBarButton.icon

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

touchBarButton.iconPosition

一个 string - 可以是 leftrightoverlay。默认为 overlay

touchBarButton.enabled

一个 boolean,表示按钮是否处于启用状态。