Zonker.in.Geneva
Zonker.in.Geneva

Reputation: 1499

Can I set the text color of individual items in a SwiftUI Segmented Picker?

I have a segmented picker in SwiftUI. I'd like each element in the picker to have its own color.

I've tried this:

struct ContentView: View {

@State private var selectedColorIndex = 0

var body: some View {
    VStack {
        Picker("Favorite Color", selection: $selectedColorIndex, content: {
            Text("Red").foregroundColor(.red).tag(0)
            Text("Green").tag(1).foregroundColor(.green)
            Text("Blue").tag(2).foregroundColor(.blue)
        })
        .pickerStyle(.segmented)

        Text("Selected color: \(selectedColorIndex)")
    }
}

}

but the items in the picker don't change color. I find this strange, since items are just simple Text views.....

Upvotes: 1

Views: 400

Answers (0)

Related Questions