简体   繁体   English

如何更改 SwiftUI Picker 菜单项中图像的颜色?

[英]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.在上面的代码中,SwiftUI 选择器不会根据前景颜色将选择器菜单项中的图标颜色更改为红色。 Any idea how to change color of an image within picker menu-item?知道如何在选择器菜单项中更改图像的颜色吗?

try using .foregroundStyle(.red, .blue) , works for me.尝试使用.foregroundStyle(.red, .blue) ,对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM