mrs.tat
mrs.tat

Reputation: 697

changing image color when clicked

I have for example this icon:

enter image description here

this is the color of the icon when its not clicked .. when i click it it will change the color as shown below:

enter image description here

what is the best way to achieve that? is there is a way to do it as a font icon and change the color of it? or shall i just change the image when clicked and unclicked?

can someone please tell me the best way to do it...

Upvotes: 1

Views: 241

Answers (1)

Lal Krishna
Lal Krishna

Reputation: 16160

Use rendered image

var renderedIcon: UIImage? = UIImage(named:"myImage")?.withRenderingMode(.alwaysTemplate )
imageView.image = renderedIcon
imageView.tintColor = //Normal Color

Change the tintColor when button clicked.

OR

You could set

myButton.setImage(UIImage(named : "unselectedImage"), forState: UIControlState.Normal)
myButton.setImage(UIImage(named : "selectedImage"), forState: UIControlState.Selected)

Upvotes: 3

Related Questions