LiveUI / Awesome

FontAwesome 6 Swift & SwiftUI implementation for iOS, tvOS & macOS
MIT License
97 stars 27 forks source link

How dynamically change icon colour? #12

Closed matt-matt1 closed 6 years ago

matt-matt1 commented 6 years ago

In my past projects, I used Font-Awesome-Icons-Version-4~. With this framework I can easily use the ver.5~ icons. Thanks - Good work. I am following an old tutorial (because I want to use a similar feature). He uses .png images (with UIImage(named: ...)). However I using Awesome.~.asImage(size: ~) and thus don't need to use UIImage. (By using it's convince method, I can specify a color.) He lists many icons and the selected one's color changes. How can I replicate this? (-.tintColor dosen't work). (-.backgroundColor works, but I don't want this.)

divadretlaw commented 6 years ago

You can either render the image with colors provided

e.g. blue user icon

imageView.image = Awesome.solid.user.asImage(size: 64.0, color: .blue, backgroundColor: .clear)

or if you want to use the .tintColor of property of UIImageView you can

imageView.tintColor = .blue
imageView.image = Awesome.solid.user.asImage(size: 64.0).withRenderingMode(.alwaysTemplate)

Then the color of the image will change when applying a new tintColor