簡體   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