6

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?

2
  • Try using .renderingMode(.template) before defining your foreground color Commented Jan 27, 2023 at 14:54
  • Tried that, it doesn't help unfortunately. Commented Jan 27, 2023 at 15:01

2 Answers 2

7

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

Sign up to request clarification or add additional context in comments.

1 Comment

make sure not to use the .tint(Color.something) modifier on the same view or a superview, as this overwrites the foregroundStyle...
-1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.