Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Background image of back button does not appear before it is touched iOS 7

I am experiencing some problems with [UIBarButtonItem appearance] for the the back button background image.

Normally (iOS 5 and iOS 6) I was able to set the background image of the back button like this:

[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

But at iOS 7 the background image does not appear on the back button. The weird thing is, that the background image actually appears when the back button has been touched once.

I have tried setting the image for all states, to test if iOS 7 was using some kind of new state for an untouched back button, but that does not seem to be the case.

Do you have any idea, what I am doing wrong?

like image 377
ThomasCle Avatar asked Sep 25 '13 08:09

ThomasCle


2 Answers

A solution which will make the background appear correctly on iOS7 is at OS 7 custom back button. It swizzles a method to fix the Apple bug (which is that they forget to call setNeedsDisplay on the private view when the background image is changed). Going borderless is probably better, if possible, but swizzling does work.

like image 56
Carl Lindberg Avatar answered Nov 25 '22 18:11

Carl Lindberg


I searched for this problem and found that you are not the only one to have the same problem. There are many others who face the same issue with UIAppearance. These are the proofs (to explain you to your client) :

  1. UIBackButton Background Image not appearing
  2. Back button is not visible in iOS 7

In this case, what you can do is to follow the Answer provided in the 2nd Link.

You can either set the backIndicatorImage property on UINavigationBar to a custom image or you can change the color of the backIndicatorImage by setting the tintColor property on UINavigationBar.

You can create a custom UIBarButtonItem and manually assign it as UINavigationItem's leftBarButtonItem.

like image 45
Bhavin Avatar answered Nov 25 '22 19:11

Bhavin