跳转到主内容

类:TouchBarButton

类:TouchBarButton

为原生 macOS 应用在 Touch Bar 中创建一个按钮

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

new TouchBarButton(options)

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

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

实例属性

以下属性可用于 TouchBarButton 的实例

touchBarButton.accessibilityLabel

一个 string,表示按钮供屏幕阅读器读取的描述。 仅当未设置 label 时才会被屏幕阅读器读取。

touchBarButton.label

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

touchBarButton.backgroundColor

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

touchBarButton.icon

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

touchBarButton.iconPosition

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

touchBarButton.enabled

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