Question

In a detail view of my app, the navigation controller's back button seems to be taking cues for its color from some ungodly manifestation. Via one path to the detail view, it's blue; via another, it's black. In either case, the back button doesn't seem to exist within the self.navigationController object.

So here's a detail view:

detail view of my app

And here's a snapshot of the navigation controller at this point:

enter image description here

I'm pretty sure I know how to change the color of this particular element, but I don't know where to find it. Ideas?

VenueTableViewController.m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *show;

    if( [self.listType isEqualToString:@"showsByRegion"] )
    {
        NSString *venueIndex = [[self.allShows allKeys] objectAtIndex:[indexPath indexAtPosition:0]];
        int index = [indexPath indexAtPosition:1];
        show = [[self.allShows objectForKey:venueIndex] objectAtIndex:index];
    } else {
        int index = [indexPath indexAtPosition:(indexPath.length - 1)];
        show = [self.showsAtVenue objectAtIndex:index];
    }

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone"
                                                         bundle:[NSBundle mainBundle]];

    detailViewController = [storyboard instantiateViewControllerWithIdentifier:@"InfoViewController"];

    detailViewController.showInfo = show;

    // Pass the selected object to the new view controller.
    [self.navigationController pushViewController:detailViewController animated:YES];

}

InfoViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.tableView = [[self.view subviews] objectAtIndex:1];

    [self createInfoViewDictionary];
    [self addTopImage];
    [self setFrameForTableView];
    [self bindLabelsToProperties];

    [self.navigationController.navigationBar setTitleTextAttributes:[SHColors sharedInstance].navBarText];
}
Was it helpful?

Solution

If you are getting different colors is because you are getting there from different viewcontrollers and those viewcontrollers have different tintColor.

Then, you need to set the color you want using:

- (void)viewDidLoad
{
    ....
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    ....
}

If you are thinking in have the same color for all the navigation bar, you can use UIAppearance proxy to set them in AppDelegate (editted: as Jordan Montel said)

OTHER TIPS

The back button on a navigation bar belongs to the view controller that the back button would send you to. i.e.

A --->B --->C

C's back button belongs to B navigation items and B's back button belongs to A navigation items.

This means that you need to check what you do in the previous View Controller.

You can set the tintColor of your navigation bar in the method didFinishLaunchingWithOptions on your AppDelegate if you want to change the whole back title color :

[[UINavigationBar appearance] setTintColor:[UIColor blackColor]];

The didFinishLaunchingWithOptions method :

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
   [[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
    return YES;
}

Set the tintColor of the navigation controller's navigation bar to whatever color you want the back button to be.

self.navigationController.navigationBar.tintColor = [UIColor whiteColor];

On iOS 6 this would set the whole bar to be white.

If you set the tint color of some superview of the navigation bar, then the back button will inherit it if it's not set.

The tintColor property of the views sets the different colors of the back button and is inherited from the superviews if none is set. You can set the tint color for your entire app by doing this in app delegate:

window.tintColor = [UIColor purpleColor];

For your situation, you need to backtrace and see where the individual colors are coming from in each navigation path and set the tintColor property of the navigation bar.

Like @micantox said the back button comes from previous view controller. So if you want to access back button visible for current controller you have to access presenting view controller, so best way to get that is:

self.presentingViewController.navigationItem.backBarButtonItem
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top