Sunday, April 21, 2013

UIButton states

UIButton allows you to set difference appearance properties (fore- and background images, title text and colour, and so on) to be displayed according to what state the button is currently in. What to my eternal shame I hadn't realised until the other day is that these states (selected, highlighted and disabled) are not mutually exclusive. This is mentioned in passing in the documentation for the UIControlState enum, but doesn't appear to be emphasised anywhere else. I blame the property-setting UI in Interface Builder for my confusion. It only allows configuration of the four main states, and not for combinations of states.

Misleading.

Combinations of states? Yes. So if you every wanted to set different disabled images for when the button is selected or unselected, you have to do the configuring in code, passing an ORed bitmask of states (such as UIControlStateSelected|UIControlStateDisabled ) to the relevant setter method.