实例方法
touch
touchBar(_:)
将触控栏内容设置为在适用时显示在触控栏中。
声明
func touchBar<Content>(_ touchBar: TouchBar<Content>) -> some View where Content : View
返回值
包含触控栏内容的视图。
参数
touchBar
触控栏显示的视图集合。
详述
使用View/touchBar(_:)
提供一组静态视图,这些视图在适当时由 Touch Bar 显示,具体取决于视图是否具有焦点。
下面的示例提供了触控栏内容in-line,它创建了触控栏显示的内容:
func selectHearts() {/* ... */ }
func selectClubs() { /* ... */ }
func selectSpades() { /* ... */ }
func selectDiamonds() { /* ... */ }
TextField("TouchBar Demo", text: $placeholder)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.focusable()
.touchBar {
Button("♥️ - Hearts", action: selectHearts)
Button("♣️ - Clubs", action: selectClubs)
Button("♠️ - Spades", action: selectSpades)
Button("♦️ - Diamonds", action: selectDiamonds)
}
可用版本
macOS 10.15+
相关用法
- Swift Optional touchBar(content:)用法及代码示例
- Swift Optional touchBarItemPresence(_:)用法及代码示例
- Swift Optional touchBarCustomizationLabel(_:)用法及代码示例
- Swift Optional touchBarItemPrincipal(_:)用法及代码示例
- Swift Optional toolbar(id:content:)用法及代码示例
- Swift Optional toolbar(content:)用法及代码示例
- Swift Optional toggleStyle(_:)用法及代码示例
- Swift Optional textSelection(_:)用法及代码示例
- Swift Optional tint(_:)用法及代码示例
- Swift Optional tabItem(_:)用法及代码示例
- Swift Optional textContentType(_:)用法及代码示例
- Swift Optional task(priority:_:)用法及代码示例
- Swift Optional transaction(_:)用法及代码示例
- Swift Optional textInputAutocapitalization(_:)用法及代码示例
- Swift Optional truncationMode(_:)用法及代码示例
- Swift Optional tag(_:)用法及代码示例
- Swift Optional transformEffect(_:)用法及代码示例
- Swift Optional task(id:priority:_:)用法及代码示例
- Swift Optional symbolVariant(_:)用法及代码示例
- Swift Optional popover(isPresented:attachmentAnchor:arrowEdge:content:)用法及代码示例
- Swift Optional mask(alignment:_:)用法及代码示例
- Swift Optional listSectionSeparatorTint(_:edges:)用法及代码示例
- Swift Optional badge(_:)用法及代码示例
- Swift Optional fullScreenCover(isPresented:onDismiss:content:)用法及代码示例
- Swift Optional keyboardType(_:)用法及代码示例
注:本文由纯净天空筛选整理自apple.com大神的英文原创作品 Optional touchBar(_:)。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。