Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set an image tint in SwiftUI?

Tags:

swiftui

I am trying to set an image tint in SwiftUI Image class

For UIKit, I can set image tint using

let image = UIImage(systemName: "cart")!.withTintColor(.blue) 

but I cant find such settings in swiftui docs

like image 483
Nic Wanavit Avatar asked Apr 11 '20 05:04

Nic Wanavit


People also ask

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.


1 Answers

On new swiftUI for set tint use:

Image("ImageName")   .foregroundColor(.red) 

Depending on the source image you may also need an additional rendering mode modifier:

Image("ImageName")   .renderingMode(.template)   .colorMultiply(.red) // or Image("ImageName")   .colorMultiply(.blue) 

And you can read this topic.

like image 172
aturan23 Avatar answered Sep 16 '22 15:09

aturan23