I am trying to build my own custom tabbar view, while building my custom buttons I am unable to change the color of Image().
struct TabBarButton: View { let title: String let icon: String var body: some View { return GeometryReader{ geometry in VStack { Image(self.icon) .resizable() .aspectRatio(contentMode: .fit) .frame(width: geometry.size.width/2, height: CGFloat(25)) .foregroundColor(.white) Text(self.title) .font(.system(size: 8)) .foregroundColor(Color.white) } } } }
I have tried foregroundColor(Color.white), accentColor(Color.white), and some different color multipliers. Is there a reason the color isn't anything other than default black? Easy fix is just to get white icons but was hoping I could solve this for now.
How to change the color of multicolor SF Symbols in SwiftUI. We can change the color of multicolor symbols by set both renderingMode and foregroundColor . <1> We enable multicolor mode by set .
The absolute simplest way to change colors of images (or icons in this case) is to use the SF Symbols where applicaple. This is a set of symbols Apple provides that can easily be used in your own app. You can download an app to help you find the correct symbol for you needs here.
Indicates whether SwiftUI renders an image as-is, or by using a different mode.
I'm not sure what are you trying to to achieve, but probably you just need template rendering mode, like
Image(self.icon) .renderingMode(.template) .foregroundColor(.white)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With