What's the default color for the background of a SwiftUI List?

Viewed 1073

I know how to change the background color of a SwiftUI Views list, but I cannot find the default color. I've tried using the MacOS 'Digital Color Meter', but it just doesn't pick it up right.

As you can see in this image, I've tried to set the background color of a list row (using .listRowBackground to the exact same of the surrounding list based off of the values from Digital Color Meter.

Does anyone actually know what the default background color actually is?

Image

2 Answers

Short answer: it looks like it is UIColor.secondarySystemBackground

Long answer:

I have tried Digital Color Meter app the sam as you did. It shows this RGB values: 242, 242, 247.

I have created such color: enter image description here

Here is my code:

import SwiftUI

extension Color {
    public static let ListBGColor = Color("ListBGColor")
}

struct ContentView: View {
    var body: some View {
        List {
                ForEach(0..<5) {_ in
                    Text("Hello, world!")
                        .padding()
                }
                .listRowBackground(Color.ListBGColor)
        }
        .listStyle(InsetGroupedListStyle())
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Result: the same color as the background (testes on Simulator and iPhone): enter image description here

The default color is different for each ListStyle and platform and I don't think SwiftUI exposes these colors. You could technically Introspect the list view and get it's background color through UIKit.

Related