What exactly IS the highlighted image in a UIImageView?

user2228497 picture user2228497 · Mar 31, 2013 · Viewed 18.8k times · Source

This question boggles my mind and I cannot find an answer. I looked all over the documentation, tried out code, and searched Google, but I can't find anything. The UIImageView in iOS programming can have an image set to it, but you can also set a highlighted image to it. What exactly is this highlighted image?

Answer

Nitin Alabur picture Nitin Alabur · Mar 31, 2013

you can set two different images to an UIImageView, one to its image property, another to its highlightedImage property.

There are many cases where you want to change the state of the image (eg: a checkmark) from off to on or vice versa. in that case, instead of you setting the UIImageView's image to the appropriate one everytime, you can just say

theCheckMarkImageView.image = regularImage;//set the regular image
theCheckMarkImageView.highLightedImage = highlightedImage;

(based on your logic show it highlighted or not).

theCheckMarkImageView.highlighted = YES/NO;

In addition to all this, do check Ethan Huang's answer about how tabelviewcell works with this property. Quite useful if you are showing different images based on cell selection.