Raymond
Raymond

Reputation: 1258

Can't change colour of image

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

Answers (2)

Ved Sharma
Ved Sharma

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

Saifullah ilyas
Saifullah ilyas

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

Related Questions