7

i'm having a problem with my UIBackbutton not appearing and i'm not sure what is causing it.

This is my code for making the back button image, it is in my first ViewController :

UIImage *backButtonHomeImage = [[UIImage imageNamed:@"backButtonImage"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonHomeImage  forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

When you first enter the next view (done by a segue from a button) the button isn't visible but the text to go back is visible. Once i've hit the back button the image appears and it stays appeared on the next time i click it.

I'm not sure if this is an issue to do with my code, or the file it's in or if it's and iOS 7 problem.

Alex Trott
  • 4,576
  • 4
  • 23
  • 30
  • 1
    I have exactly the same issue and the issue occured with iOS 7. I made a lot of search about it and so far found no solution. Leaving blue default backBarButtonItem and removing your custom backgroundImage might help you for now. – Engnyl Sep 13 '13 at 12:08
  • Quiet a common issue with custom graphics on iOS7. Facing the same trouble – eagle.dan.1349 Oct 17 '13 at 07:54
  • It's an Apple bug; solution at [iOS 7 custom back button](http://stackoverflow.com/questions/18824887/ios-7-custom-back-button/19452709). – Carl Lindberg Jan 13 '14 at 23:54

4 Answers4

2

You may have more luck using a UIBarButtonItem and setting the back button background explicitly.

The appearance proxy has been unreliable in my own attempts to get a back button working with iOS 7. I experienced the same issue with the background not showing up properly first time showing the button.

0

If you just need to change the colour, try this[[UINavigationBar appearance] setTintColor:[UIColor redColor]];

JerryZhou
  • 4,566
  • 3
  • 37
  • 60
0

If you want to change back button image you just need to write this 2 lines of code:

[self.navigationBar setBackIndicatorImage:[UIImage imageNamed:@"icon-back"]];
[self.navigationBar setBackIndicatorTransitionMaskImage:[UIImage imageNamed:@"icon-back"]];

And if you create sub class of UINavigationController it makes easy to customize you navigationbar and push & pop controllers

sonifex
  • 280
  • 1
  • 2
  • 14
-1

Try this:

self.navigationItem.hidesBackButton = NO;

if you're trying to add it to the Navigation bar then:

 UIImage* image4 = [UIImage imageNamed:@".....png"];
    button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 26, 26)];
    [button setBackgroundImage:....png forState:UIControlStateNormal];
    [button addTarget:self action:@selector(Selector)
         forControlEvents:UIControlEventTouchUpInside];
    [button setShowsTouchWhenHighlighted:YES];

    UIBarButtonItem *action = [[UIBarButtonItem alloc] initWithCustomView:button];
    NSArray *arr =[[NSArray alloc]initWithObjects:action, nil];
    self.navigationItem.rightBarButtonItems = arr;
J-LO
  • 229
  • 1
  • 3
  • 17