How to change a List’s background color in SwiftUI

Federica Benacquista
2 min readMay 31, 2022

In my journey in learning SwiftUI I’m encountering small issues like not knowing how to change the background color of a List.

After some research I can now fully customise my Lists.

Changing the background color of a List:

There are several approaches you can go for:

  1. Initialise the TableView color. you can either do this in the struct you placed the list in or in the App file. The latter approach will set the color for all of the Lists in you app
init(){
UITableView.appearance().backgroundColor = UIColor.purple
}

2. The above property can also be set like this:

List{}
.onAppear{
UITableView.appearance().backgroundColor = .purple
}

3. My favorite one, set the List’s style to .plain and change the background color

List{}
.listStyle(.plain)
.background(Color.white.opacity(0.3))
Slayed

Changing the cells’ background color:

Let’s assume you create your own custom cells for your list. You might say “Yeah let’s set the background color to green”, nice one, anyway, after doing so, you’ll notice that the actual cell’s background will be white and it will contain a…

--

--

Federica Benacquista

I’m a self taught iOS developer and soon to be entrepreneur. I like to explain tricky concepts as easily as possible and it’s exactly what I do here.