spt025
spt025

Reputation: 2304

How to change color of Image within SwiftUI Picker menu-item?

I am writing a picker and it lists a bunch of icons.

Picker("Icons ", selection: $selectedIcon) {
    ForEach(icons, id: \.self) { icon in
        HStack {
            Image(systemName: icon)
            .foregroundColor(Color.red) // This doesn't work
        }.padding()
    }
}

In the above code, SwiftUI picker doesn't change the color of the icon to red in the picker's menu-item as per foreground color. Any idea how to change color of an image within picker menu-item?

Upvotes: 5

Views: 1475

Answers (2)

Mohammed Shaheen
Mohammed Shaheen

Reputation: 1

Use .foregroundStyle(Color1, Color2) But only Color1 will be displayed.

Upvotes: -1

try using .foregroundStyle(.red, .blue), works for me.

Upvotes: 6

Related Questions