實例方法
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(_:)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。