Can't change List background color in iOS 16

I can't seem to find a way to change List's background color. Modifier .background() has no effect on List background color. Putting List in a ZStack & applying .background modifier to it also has no effect

I know that starting with iOS 16 List is backed by UICollectionView so old tricks with .appearance() does not work anymore. Using ZStack with .plain list style also has no effect.

Intospecting view hierarchy kinda works but List resets its bg color on update

List is such a fundamental component and having no ability to change its background color is very limiting

This is simply nuts IMO :) I can't figure out how something SO basic can be left out, even for a beta release... If this won't be addressed I have to drop two years of SwiftUI development and switch back (and forever) to UIKit :( I have lists all over my apps and now they are all broken...

Did you try using listRowBackground ?

As in the following (tested, works):

struct ContentView: View {
    @State var rows: [RowModel] = [
        RowModel(name: "Orange"),
        RowModel(name: "Apple"),
        RowModel(name: "Lemon"),
    ]   

    var body: some View {
        NavigationView {
            List {
                ForEach($rows) { $row in
                    TextField("Fruit", text: $row.name)
                }.listRowBackground(Color.blue)
            }
            .navigationTitle("Fruit List")
        }
        .navigationViewStyle(.stack)
    }
}

Or do you look for something different ?

I think Vlad wants to change the whole background not of some cells. We found a way using Introspect. However, we are not sure if this is in any way "legal".

extension View {
    @warn_unqualified_access
    @ViewBuilder
    func listBackgroundColor(_ color: Color) -> some View {
        introspectViewController { inspectSubView($0.view, backgroundColor: .init(color)) }
    }

    // MARK: Helper

    private func inspectSubView(_ view: UIView, backgroundColor: UIColor) {
        for subview in view.subviews {
            if NSStringFromClass(type(of: subview)).contains("UICollectionViewListLayoutSectionBackgroundColorDecorationView") {
                subview.backgroundColor = backgroundColor
                return
            }
            inspectSubView(subview, backgroundColor: backgroundColor)
        }
    }
} 

New in iOS 16 beta 3, two new modifiers!

You can use them to set a background colour for a list:

List {
    ...
}
.scrollContentBackground(Color.red) // using .red results in an error

or set a custom background view:

List {
    ...
}
.scrollContentBackground(.hidden)
.background {
    Image(systemName: "list.bullet")
        .resizable()
        .scaledToFit()
        .padding()
}
Can't change List background color in iOS 16
 
 
Q