繁体   English   中英

如何在 SwiftUI WatchOS App 中更改列表的行背景颜色

[英]How can I change the List's row background color in SwiftUI WatchOS App

在此处查看预览屏幕截图

我不希望我的ImageText像我的按钮那样有灰色背景。 我正在使用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM