[英]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.