The following solution changes all sorts of colors in SwiftUI's List
without changing the global appearance()
of the UITableView
. You can change the cell background as well as the List background.
import SwiftUI
struct ContentView: View {
var listItems: [String] = ["A", "B", "C"]
var body: some View {
List {
ForEach(listItems, id: \.self) { item in
Text(item)
}
.listRowBackground(Color.purple) // Applying the list cell background color
}
.scrollContentBackground(.hidden) // Hides the standard system background of the List
.background(Color.teal) // Applying list background color
}
}