How to customize picker page selection

Viewed 97

I have a standard picker in a list, customized in dark colors. When I tap on the picker, it opens the page with the choices, but the background is white, and I would like it to be black.

Didn't succeed to find the appropriate settings :( Thanks for your help

My code :

import SwiftUI
let choices = ["red", "blue", "yellow"]

struct test4: View {
    
    @State private var myColor: String = choices[0]
    
    var body: some View {
        VStack {
            List {
                Picker(selection: $myColor, label: Text("Type")) {
                    ForEach(choices, id: \.self) { col in
                        Text(col).foregroundColor(Color.gray)
                    }
                }
                .listRowBackground(Color.row)
            }
        }
        .background(Color.black)
    }
}

Page with the picker Page1

Picker selection Page2

1 Answers

Use instead preferred color scheme, like

    VStack {
       // List here ...
    }
    //.background(Color.black)
    .preferredColorScheme(.dark)    // << use this !!

demo

Related