0

I've customized UIBarButtonItem in my AppDelegate.m using UIAppearance and all the bar buttons are showing the correct images in normal and selected states.

I want "Done" and "Save" buttons to use a different image (so they appear to be blue instead of gray), so I use -setBackgroundImage: forState: barMetrics to set two different images for UIControlStateNormal and UIControlStateSelected in -viewDidLoad.

The image for UIControlStateNormal is working fine, but the UIControlStateSelected one isn't showing, instead it shows the original image I used for selected states in AppDelegate.m. If I comment out the original image the new (blue) one is shown properly.

What's the proper way to set different background images for specific buttons?

James
  • 762
  • 8
  • 22

1 Answers1

1

I believe UIControlStateHighlighted is what you are looking for.

A UIBarButtonItem goes into the highlighted state whenever it receives the user touch. UIControlStateSelected is typically for UI elements which toggle between two states.

brynbodayle
  • 6,546
  • 2
  • 33
  • 49
  • Thank you! I tried `UIControlStateSelected` and it worked for the plain style bar buttons that I customized in AppDelegate.m so I thought it was the right one. Thanks for clearing it up. – James Sep 26 '12 at 16:24
  • Btw, do you know if there's a way to set all `UIBarButtonItemStyleDone`with a custom image? I tried asking in this question but got no response: http://stackoverflow.com/questions/12583574/customizing-uibarbuttonitem-done-style-and-plain-style-separately-using-uiap – James Sep 26 '12 at 17:01