15

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?

ThomasCle
  • 6,792
  • 7
  • 41
  • 81
  • It's possible to fix the display glitch with a swizzled method; see my response at http://stackoverflow.com/a/19452709/1754225 . But some of the other alternatives might be preferable. – Carl Lindberg Oct 18 '13 at 15:14
  • Unfortunately I am also facing the same problem. Did you get any solution for this? – Sourabh Bhardwaj Oct 29 '13 at 10:49
  • No I didn't. I had to create a custom back-button as a `UIButton` and set it as `leftBarButtonItem` to work around it. :-( – ThomasCle Oct 29 '13 at 11:55

5 Answers5

1

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.

Community
  • 1
  • 1
Bhavin
  • 27,155
  • 11
  • 55
  • 94
1

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.

Community
  • 1
  • 1
Carl Lindberg
  • 2,902
  • 18
  • 22
0

try to change the tint color of the button. There is some issue in iOS 7 for UIBarButton

Ekra
  • 3,241
  • 10
  • 41
  • 61
  • Can you give some evidence for the claim? I am having the same issue, and I have to explain it to the client. That's why I am asking you :) – Popara Sep 26 '13 at 15:55
  • first try ti yourself and if it works than u can explain it to client as well – Ekra Sep 28 '13 at 13:07
0

I implemented a really nice solution that works under ios5+ here:

Back button item strangely disappearing under iOS7

Community
  • 1
  • 1
0

To work with ios7 you need to use

    UIImage *backButton = [[UIImage imageNamed:@"icon_back" resizableImageWithCapInsets:UIEdgeInsetsZero];
if ([UINavigationBar instancesRespondToSelector:@selector(setBackIndicatorImage:)]) {
    [[UINavigationBar appearance] setBackIndicatorImage:backButton];
     [[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:backButton];
}else{
//ios 5 and 6 code
}
ferbass
  • 859
  • 5
  • 17