Custom UINavigationController back buttons under iOS7

When you first create / get a reference to the navigation controller, set a global custom back image (replaces the chevron) with:

[self.navigationController.navigationBar setBackIndicatorImage:
    [UIImage imageNamed:@"CustomerBackImage"]];
[self.navigationController.navigationBar setBackIndicatorTransitionMaskImage:
    [UIImage imageNamed:@"CustomerBackImage"]];

The title of the back button is owned by the view that it points to, not the current view. You can make it blank by calling

self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc]
    initWithTitle:@""
    style:UIBarButtonItemStylePlain
    target:nil
    action:nil];

in the view that the back button points to. So call it in prepareForSegue or before pushViewController:animated: or something. Setting a view controller’s title programmatically seems to reset it, so set it after setting the title.

You’ll see lots of advice to set self.navigationItem.leftBarButtonItems (which breaks swipe-to-go-back) then mess with interactivePopGestureRecognizer to fix swipe-to-go-back (which has some exciting doesn’t quite work right edge case problems). Don’t do that. Do this.

Published by Tom Insam

programming / london / san francisco / bacon

Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s