How to change the tintColor of UIImage in iOS and WatchKit?
Hello colleagues! I'm new to Swift and can't figure out how to change the color of icons in an app. I have a UIImageView with an image, and I want to dynamically change its color depending on the theme or state (e.g., active/inactive button). I tried simply setting the `tintColor` property of UIImageView, but the color doesn't change — the icon remains the original (black or gray).
Here's my code:
```swift
let imageView = UIImageView(image: UIImage(named: "myIcon"))
imageView.tintColor = .red
```
Nothing happens. I googled it — they say I need to use `withRenderingMode(.alwaysTemplate)`. I tried:
```swift
let image = UIImage(named: "myIcon")?.withRenderingMode(.alwaysTemplate)
imageView.image = image
imageView.tintColor = .red
```
This worked in iOS, but in the app