79167157

Date: 2024-11-07 15:39:53
Score: 0.5
Natty:
Report link

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
    }
}

Output: Demo

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Mahi Al Jawad