實例方法
list
listRowBackground(_:)
在列表行項目後麵放置一個自定義背景視圖。
聲明
func listRowBackground<V>(_ view: V?) -> some View where V : View
返回值
以view
作為背景視圖的列表行視圖。
參數
view
View
用作列表行視圖後麵的背景。
詳述
使用listRowBackground(_:)
將自定義背景視圖放置在列表行項目後麵。
在下麵的示例中,Flavor
枚舉為列表項提供內容。 SwiftUI ForEach
結構計算Flavor
枚舉的每個元素的視圖,並使用結果文本提取其每個元素的原始值以創建每個列表行項目。 listRowBackground(_:)
修飾符然後將您提供的視圖放置在每個列表行項的後麵:
struct ContentView: View {
enum Flavor: String, CaseIterable, Identifiable {
var id: String { self.rawValue }
case vanilla, chocolate, strawberry
}
var body: some View {
List {
ForEach(Flavor.allCases) {
Text($0.rawValue)
.listRowBackground(Ellipse()
.background(Color.clear)
.foregroundColor(.purple)
.opacity(0.3)
)
}
}
}
}
可用版本
iOS 13.0+, iPadOS 13.0+, macOS 10.15+, Mac Catalyst 13.0+, tvOS 13.0+, watchOS 6.0+
相關用法
- Swift Optional listRowSeparator(_:edges:)用法及代碼示例
- Swift Optional listRowSeparatorTint(_:edges:)用法及代碼示例
- Swift Optional listRowInsets(_:)用法及代碼示例
- Swift Optional listSectionSeparatorTint(_:edges:)用法及代碼示例
- Swift Optional listSectionSeparator(_:edges:)用法及代碼示例
- Swift Optional lineSpacing(_:)用法及代碼示例
- Swift Optional lineLimit(_:)用法及代碼示例
- Swift Optional luminanceToAlpha()用法及代碼示例
- Swift Optional labelsHidden()用法及代碼示例
- Swift Optional labelStyle(_:)用法及代碼示例
- Swift Optional layoutPriority(_:)用法及代碼示例
- Swift Optional symbolVariant(_:)用法及代碼示例
- Swift Optional popover(isPresented:attachmentAnchor:arrowEdge:content:)用法及代碼示例
- Swift Optional mask(alignment:_:)用法及代碼示例
- Swift Optional badge(_:)用法及代碼示例
- Swift Optional fullScreenCover(isPresented:onDismiss:content:)用法及代碼示例
- Swift Optional keyboardType(_:)用法及代碼示例
- Swift Optional clipShape(_:style:)用法及代碼示例
- Swift Optional preferredColorScheme(_:)用法及代碼示例
- Swift Optional background(_:ignoresSafeAreaEdges:)用法及代碼示例
- Swift Optional saturation(_:)用法及代碼示例
- Swift Optional focusSection()用法及代碼示例
- Swift Optional overlay(alignment:content:)用法及代碼示例
- Swift Optional colorMultiply(_:)用法及代碼示例
- Swift Optional confirmationDialog(_:isPresented:titleVisibility:presenting:actions:message:)用法及代碼示例
注:本文由純淨天空篩選整理自apple.com大神的英文原創作品 Optional listRowBackground(_:)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。