Is there a way to change the background color of a List in SwiftUI? 2020 (iOS 14)

Viewed 713

I would like to change the background color of the List. Currently, I am using UITableView.appearance().backgroundColorto change the color and it works pretty well. However, with iOS 14 Apple is recommending everyone to go for collectionViews and I just don't know if I should stick with this or not.

I am looking for other ways to change the background color of the list. Here is the issue: I would like the background to be the same color as the nav bar or the Test row background color but I get a full black background.

enter image description here

On writing, the above UITableView.appearance().." in .onAppear' I get the desired result:

enter image description here

So my question is, Is there a better more iOS 14 way of achieving this?

1 Answers

Swift 5, Xcode 12, iOS 14

I was able to accomplish this using the Introspect library with a few lines of code:

List {
...
}
.introspectTableView { tableView in
  tableView.backgroundColor = .yellow
}
Related