首页 > 解决方案 > 如何在swiftUI中将背景颜色添加到列表中

问题描述

我想将背景白色更改为 SwiftUI 中列表的另一种颜色

点击这里

List(listOfItems) { item in
    Group {
        HStack {
            item.iconImage.padding()
            Text(item.text).fontWeight(.regular).foregroundColor(Color("smalltext")).font(.system(size: 25))
            Spacer()
            Button(action: {
                
            }) {
                Image("back")
            }
        }.padding().background(Color("bg"))
    }.listRowBackground(Color("bg"))
}.background(Color("bg"))

标签: swiftui-listswiftui

解决方案


如果要更改背景颜色,可以在包含List. 将此init块添加到您的View. 这会将所有内容更改为绿色。

init() {
   UITableViewCell.appearance().backgroundColor = .green
   UITableView.appearance().backgroundColor = .green
}

推荐阅读