Reputation: 129
I have a black icon that and I use it to image button. Programatically I tint this button gray. When the screen is displayed, the button is gray, but once I tap button, it turns black again.
This is how I tint the button:
addQuantityButton.imageView?.image = addQuantityButton.imageView?.image?.withRenderingMode(.alwaysTemplate)
addQuantityButton.imageView?.tintColor = .gray
Thanks!
Upvotes: 0
Views: 77
Reputation: 769
Please try this and it will resolve your issue.
Image Mode
addQuantityButton.setImage(addQuantityButton.currentImage!.withRenderingMode(UIImage.RenderingMode.alwaysTemplate), for: .normal)
addQuantityButton.tintColor = .gray
Background Image mode
addQuantityButton.setImage(addQuantityButton.currentBackgroundImage!.withRenderingMode(UIImage.RenderingMode.alwaysTemplate), for: .normal)
addQuantityButton.tintColor =.gray
Upvotes: 2
Reputation: 86
Try this:
setImage(image.withRenderingMode(.alwaysTemplate), for: .highlighted)
Upvotes: 0