【问题标题】:How to add background Color to List in swiftUI如何在swiftUI中将背景颜色添加到列表中
【发布时间】:2020-07-27 19:49:49
【问题描述】:

我想将背景白色更改为 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-list swiftui


    【解决方案1】:

    如果您想更改背景颜色,您可以在包含List 的视图中执行以下操作。将此init 块添加到您的View 中。这会将所有内容更改为绿色。

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

    【讨论】:

    • 对我没用
    猜你喜欢
    • 1970-01-01
    • 2019-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-22
    • 1970-01-01
    • 2023-01-09
    相关资源
    最近更新 更多