当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Swift Optional touchBarItemPrincipal(_:)用法及代码示例


实例方法

touchBarItemPrincipal(_:)

设置对该 Touch Bar 具有特殊意义的主要视图。

声明

func touchBarItemPrincipal(_ principal: Bool = true) -> some View

返回值

一个触控栏视图,其中一个元素位于触控栏行的中心。

参数

principal

一个布尔值,指示与其他视图相比是否在触控栏中突出显示此视图。

详述

使用 touchBarItemPrincipal(_:) 将视图指定为触控栏中的重要视图。目前,该视图将放置在行的中心。

下面的示例将最后一个按钮设置为 Touch Bar 视图的主要按钮。


let touchBarItems = TouchBar(id: "myBarItems") {
    Button("♣️", action: {})
    Button("♥️", action: {})
    Button("♠️", action: {})
    Button("♦️", action: {})
       .touchBarItemPrincipal(true)
}


TextField("TouchBar Demo", text: $placeholder)
    .frame(maxWidth: .infinity, maxHeight: .infinity)
    .focusable()
    .touchBar(touchBarItems)

可用版本

macOS 10.15+

相关用法


注:本文由纯净天空筛选整理自apple.com大神的英文原创作品 Optional touchBarItemPrincipal(_:)。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。