Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI - Unable to change color of Image icon

Tags:

swiftui

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.

like image 996
C. Skjerdal Avatar asked Jan 29 '20 19:01

C. Skjerdal


People also ask

How do I change the color of my icons in SwiftUI?

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 .

Can we change image color in Swift?

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.

What is rendering mode in SwiftUI?

Indicates whether SwiftUI renders an image as-is, or by using a different mode.


1 Answers

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) 
like image 171
Asperi Avatar answered Sep 18 '22 13:09

Asperi