![](/img/trans.png)
[英]How can I make a SwiftUI List row background color extend the full width, including outside of the safe area
[英]How can I change the List's row background color in SwiftUI WatchOS App
我不希望我的Image
或Text
像我的按鈕那樣有灰色背景。 我正在使用List
,以便用戶可以在按鈕之間向下滾動。
struct ContentView: View {
var body: some View {
List {
Image("Forest1")
.resizable()
.aspectRatio(contentMode: .fill)
.padding(.all)
.background(Color.black.ignoresSafeArea())
Text("Welcome Back!")
.padding()
.background(Color.black.ignoresSafeArea())
Button(action: PLACEHOLDER) {
Text("Shake Tree")
}
Button(action: PLACEHOLDER) {
Text("Open Forge")
}
Button(action: PLACEHOLDER) {
Text("Open Cabin")
}
Button(action: PLACEHOLDER) {
Text("Open Map")
}
}
}
}
您可以使用.listRowBackground(Color.black)
將默認列表行背景顏色更改為任何顏色。
struct ContentView: View {
var body: some View {
List {
Image("Forest1")
.resizable()
.aspectRatio(contentMode: .fill)
.padding(.all)
.background(Color.black.ignoresSafeArea())
.listRowBackground(Color.black) // <- Here
Text("Welcome Back!")
.padding()
.background(Color.black.ignoresSafeArea())
.listRowBackground(Color.black) // <- Here
Button(action: PLACEHOLDER) {
Text("Shake Tree")
}
Button(action: PLACEHOLDER) {
Text("Open Forge")
}
Button(action: PLACEHOLDER) {
Text("Open Cabin")
}
Button(action: PLACEHOLDER) {
Text("Open Map")
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.