Search code examples
swiftui-listswiftui

How to add background Color to List in swiftUI


I want to change the background white to an another color to the List in SwiftUI

Click Here

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"))

Solution

  • If you want to change the background color you would do the following in the view containing the List. Add this init block in your View. This will change everything to green.

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