這可能是一個老問題了。但我仍然找不到可行的解決方案。
就像下圖一樣。我想讓藍色背景擴展到頂部的整個串列視圖。但是,SwiftUI 會自動添加兩個白色背景(可能來自 UICollection View 或某處)。有誰知道如何從 SwiftUI 的串列中洗掉那些白色背景?


重現問題的最小代碼。這里的兩個背景是黑色的,并擋住了藍色背景。
struct ContentView: View {
var body: some View {
List {
Text("Hello World")
Text("Hello World")
Text("Hello World")
}
.background(Color.blue)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}

uj5u.com熱心網友回復:
在 iOS 16 上,除了設定背景顏色外,您還需要使用.scrollContentBackground(.hidden) :
List {
Text("Hello World")
Text("Hello World")
Text("Hello World")
}
.background(Color.blue)
.scrollContentBackground(.hidden)
在 iOS 16 之前,有一些變通方法,最可靠的一種是回溯(示例)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/517741.html
標籤:迅速列表迅捷wwdc
