I wish to change the color or tint of an image that is inside of a button when that button is pressed. I have learned of various code to change the tint of a UIImageView but that does not seem to work for a UIImage.
The code for the tinting of a UIImageView seems to be this for Swift 3:
but it doesn't seem to work for just an image inside a button. Can anyone suggest how to do it? I have looked at various extensions but none of them seem to work or I am not applying the code correctly. thanks for your help.
[doublepost=1478162754][/doublepost]I have found some code that works partially however it blots the image itself and all you can see is the color. Is there any way to fix this?
The code for the tinting of a UIImageView seems to be this for Swift 3:
Code:
theImageView.image = theImageView.image!.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)
theImageView.tintColor = UIColor.redColor()
theImage.setTintColor(UIColor.redColor())
but it doesn't seem to work for just an image inside a button. Can anyone suggest how to do it? I have looked at various extensions but none of them seem to work or I am not applying the code correctly. thanks for your help.
[doublepost=1478162754][/doublepost]I have found some code that works partially however it blots the image itself and all you can see is the color. Is there any way to fix this?
Code:
mybuttonname.setImage(mypicturename?.withRenderingMode(UIImageRenderingMode.alwaysTemplate), for: .normal)
mybuttonname.tintColor = UIColor.orange
Last edited: