UIBackButton Background Image not appearing
Asked Answered
P

4

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.

Petasus answered 13/9, 2013 at 11:56 Comment(3)
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.Rubbery
Quiet a common issue with custom graphics on iOS7. Facing the same troubleShavonda
It's an Apple bug; solution at iOS 7 custom back button.Placet
C
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.

Caste answered 16/9, 2013 at 19:23 Comment(0)
T
0

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

Typeset answered 24/9, 2013 at 3:25 Comment(0)
S
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

Submersed answered 22/2, 2016 at 8:43 Comment(0)
O
-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;
Openair answered 13/9, 2013 at 12:2 Comment(1)
The button you create with this code doesn't work as a backBarButton though.Petasus

© 2022 - 2024 — McMap. All rights reserved.