【问题标题】:How can I change the List's row background color in SwiftUI WatchOS App如何在 SwiftUI WatchOS App 中更改列表的行背景颜色
【发布时间】:2021-02-10 21:58:51
【问题描述】:

See preview screenshot here

我不希望我的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")
      }
    }
  }
}

【问题讨论】:

    标签: swift swiftui


    【解决方案1】:

    您可以使用.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")
          }
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-09-22
      • 1970-01-01
      • 1970-01-01
      • 2021-02-11
      • 2020-01-01
      • 2022-08-12
      • 1970-01-01
      • 1970-01-01
      • 2020-01-21
      相关资源
      最近更新 更多