Reputation: 1499
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