0

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 
5
  • It should work. I tried your code and it's working for me. You can check image name in asset and code. Commented Aug 3, 2020 at 16:50
  • I think something is wrong with image itself not sure what. Commented Aug 3, 2020 at 17:03
  • Can you please send me image? I can check and let you know. Commented Aug 3, 2020 at 17:04
  • imgur.com/a/Df8PgIH Commented Aug 3, 2020 at 17:08
  • Just posted my answer. please try that. The image is having transparency that's why color will not be visible properly. Commented Aug 3, 2020 at 17:16

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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 } 

}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.