Question

I have a UIBarButtonItem containing a button, on which I've set custom background images for the pressed/unpressed states. The pressed image is moved down by 4px, so the text when it's unpressed looks off center vertically. I know I can use [button setTitleEdgeInsets:UIEdgeInsetsMake(10.0, 10.0, 0.0, 0.0)] to change the position of the text label, but can I do this only for a certain control state (unpressed)?

If this means subclassing UIButton, would I have t handle all of the drawing myself in drawRect?

Was it helpful?

Solution

No, you shouldn't have to handle the drawing yourself if you subclassed UIButton. One approach would to simply key-value-observe the enabled and selected properties within your subclass, and then just adjust the edge insets to an appropriate value whenever the state changes. This question here relates to observing the button for state changes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top