Reputation: 1258
I've png images in assets I've set Render As Template
image. Following is the code. Why doesn't it set the image to be white? How to fix it?
@IBOutlet weak var iconImageView: UIImageView!
iconImageView.image = UIImage(named: "ico")?.withRenderingMode(.alwaysTemplate)
iconImageView.tintColor = .white
Upvotes: 0
Views: 257
Reputation: 769
Your code is fine and it's working perfectly. The only problem is the image is having transparency that's why color is not visible properly.
Upvotes: 2
Reputation: 464
it should work . try this, almost same.
extension UIImageView {
func setImageColor(color: UIColor) {
let templateImage = self.image?.withRenderingMode(UIImage.RenderingMode.alwaysTemplate)
self.image = templateImage
self.tintColor = color
}
}
Upvotes: 0