239

How can I customize the navigation back button in iOS 7 and above without title? (i.e. with the arrow only)

self.navigationItem.leftBarButtonItem = self.editButtonItem;

I'm just wondering if they have any self.backButtonItem;

OR

something like this?

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]
                   initWithBarButtonSystemItem:UIBarButtonSystemItemBACK 
                   target:self action:@selector(back)];
2
  • 3
    You can use @hiroshi answer + navigation bar tintColor property to make chevron with custom color and without any titles Sep 26, 2013 at 9:55
  • For those who have a tab bar, and you don't want the text of back button, the fix is: in the viewDidLoad() of the TabBarController put: self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
    – Borzh
    Jul 1, 2017 at 1:10

36 Answers 36

319

It's actually pretty easy, here is what I do:

Objective C

// Set this in every view controller so that the back button displays back instead of the root view controller name
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];

Swift 2

self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .Plain, target: nil, action: nil)

Swift 3

self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)

Put this line in the view controller that is pushing on to the stack (the previous view controller). The newly pushed view controller back button will now show whatever you put for initWithTitle, which in this case is an empty string.

12
  • 3
    I used this but the title comes and disappears in an animated fashion?? Nov 2, 2013 at 4:21
  • 7
    Thanks Kyle! I've been looking for a way to rename the default back button in iOS 7. I put this in my prepareForSegue in the view controller and it worked perfectly.
    – yiwei
    Jan 6, 2014 at 15:32
  • 1
    @user1010819 This is the expected behavior, barButtonItems will animate in and out when switching view controllers. What are you trying to accomplish? Jan 7, 2014 at 1:48
  • 1
    @YiweiGao No problem! It is just another one of those things that if you know the right code, its pretty simple! I am glad it helped! Jan 7, 2014 at 1:48
  • 3
    I feel like this needs an update, it just shows nothing right now, the arrow is not there by default? Mar 28, 2015 at 10:23
196

I found an easy way to make my back button with iOS single arrow.

Let's supouse that you have a navigation controller going to ViewA from ViewB. In IB, select ViewA's navigation bar, you should see these options: Title, Prompt and Back Button.

ViewA navigate bar options

ViewA navigate bar options

The trick is choose your destiny view controller back button title (ViewB) in the options of previous view controller (View A). If you don't fill the option "Back Button", iOS will put the title "Back" automatically, with previous view controller's title. So, you need to fill this option with a single space.

Fill space in "Back Button" option

Fill space in "Back Button" option

The Result:

The Result:

8
  • Welcome to Stack Overflow. If you haven't already, take a look at what we're tour, and read some of the articles in the help center about how we work and some of the community customs here. If you need any help with the site's functions, don't be afraid to search up, then ask a question on Meta Stack Overflow (if you still couldn't find an answer). Thanks, and good luck! Anyway, you can post your images now... :) Nov 30, 2013 at 13:25
  • 53
    it works, just pay attention - you need to set "Back Button" for previous controller (e.g. for rootViewController in your navigation controller)
    – evfemist
    Feb 17, 2014 at 20:42
  • Make sure you don't have "hidesBackButton" set to TRUE on the navigation item in ViewA
    – shim
    May 11, 2014 at 23:20
  • It appears to me that this works if the presenting controller's title is long enough - if it's a short title it will be used instead.
    – amergin
    Aug 29, 2014 at 10:11
  • 1
    for me it only works when both the source and destination ViewController's NavigationItem have Back Button set to a single space character (i.e. both ViewA and ViewB)
    – dcestari
    Dec 30, 2014 at 1:10
77

Just use an image!

OBJ-C:

- (void)viewDidLoad {
     [super viewDidLoad];
     UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Icon-Back"]
                                                                                        style:UIBarButtonItemStylePlain
                                                                                       target:self.navigationController
                                                                                       action:@selector(popViewControllerAnimated:)];
     self.navigationItem.leftBarButtonItem = backButton;
}

SWIFT 4:

let backBTN = UIBarButtonItem(image: UIImage(named: "Back"), 
                              style: .plain, 
                              target: navigationController, 
                              action: #selector(UINavigationController.popViewController(animated:)))
navigationItem.leftBarButtonItem = backBTN
navigationController?.interactivePopGestureRecognizer?.delegate = self

Icon-Back.png

Icon-Back

[email protected]

Icon-Back@2x

[email protected]

Icon-Back@23x

3
  • 5
    With this solution you seem to loose the "swipe to go back" functionality.
    – j7nn7k
    Dec 7, 2016 at 10:33
  • 17
    navigationController?.interactivePopGestureRecognizer?.delegate = self does the trick to keep the swipe back gesture Jan 23, 2017 at 17:01
  • I've been searching for this answer, perhaps all my life, namely the action selector.
    – Des
    Jan 9, 2019 at 10:01
29

iOS7 has new interface rules, so It's better to keep at least the back arrow when you push a UIView. It's very easy to change the "back" text programmatically. Just add this code before push the view (Or prepareForSegue if you are using StoryBoards):

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
      self.navigationItem.backBarButtonItem=[[UIBarButtonItem alloc] initWithTitle:@"NEW TITLE" style:UIBarButtonItemStylePlain target:nil action:nil];
}

This will change the default "Back" text, but will keep the iOS7 styled back arrow. You can also change the tint color for the back arrow before push the view:

- (void)viewDidLoad{
     //NavBar background color:
     self.navigationController.navigationBar.barTintColor=[UIColor redColor];
//NavBar tint color for elements:
     self.navigationController.navigationBar.tintColor=[UIColor whiteColor];
}

Hope this helps you!

1
  • 2
    This works really well and seems better than the other options. For instance, the title never needs to be reset to the previous value, unlike some of the other answers.
    – pr1001
    Nov 20, 2013 at 14:56
26

Nothing much you need to do. You can achieve the same through storyboard itself.

Just go the root Navigation controller and give a space. Remember not to the controller you wanted the back button without title, but to the root navigation controller.

As per the image below. This works for iOS 7 and iOS 8

3
  • I've try it, It works. But I still can't change the title in the code. Jul 18, 2016 at 3:26
  • Worked with XCode7, but doesn't work anymore in xCode8 -> ios10.X, I've used @iwasrobbed method
    – LucioB
    Feb 8, 2017 at 10:52
  • All genius is simple!
    – Illya Krit
    Sep 20, 2017 at 10:37
22

While Kyle Begeman's answer totally does the trick, it is quite annoying to have this code in every view controller possible. I ended up with a simple UINavigationItem category. Beware, here be dragons! Sorry, I mean, swizzling:

#import <objc/runtime.h>

@implementation UINavigationItem (ArrowBackButton)

static char kArrowBackButtonKey;

+ (void)load {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        Method m1 = class_getInstanceMethod(self, @selector(backBarButtonItem));
        Method m2 = class_getInstanceMethod(self, @selector(arrowBackButton_backBarButtonItem));
        method_exchangeImplementations(m1, m2);
    });
}

- (UIBarButtonItem *)arrowBackButton_backBarButtonItem {
    UIBarButtonItem *item = [self arrowBackButton_backBarButtonItem];
    if (item) {
        return item;
    }

    item = objc_getAssociatedObject(self, &kArrowBackButtonKey);
    if (!item) {
        item = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleBordered target:nil action:NULL];
        objc_setAssociatedObject(self, &kArrowBackButtonKey, item, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    }
    return item;
}

@end
4
  • 1
    I upvoted but then decided to use a simpler hack instead -- [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-1000, -1000) forBarMetrics:UIBarMetricsDefault]; (source) -- might be a bit less elegant, but swizzling felt like overkill
    – dmur
    Mar 31, 2014 at 19:34
  • 2
    Seriously y'all...don't pass go on any other solution. Implement the solution @nicky posted as a Category and don't think twice. This is a great reusable solution that can be implemented app wide if you add this Prefix.pch file. Apple encourages using categories to add Methods to Existing Classes you should take advantage of this when possible.
    – zmonteca
    Mar 10, 2015 at 1:10
  • This is the best solution in my opinion, anyway the "method_exchangeImplementation" is a bit unsafe, take a look at this: Right way to swizzle and this NSHipster swizzling guide Jan 13, 2016 at 11:27
  • @AlessandroOrrù In this particular case, this should be safe because the swizzled method is UINavigationItem's very own method, there's no inheritance involved. And _cmd is very unlikely to be involved in a getter. Anyway though, it's a good point. So y'all, if you have any of these numerous swizzling helpers in your project, make sure you use it here too. Jan 13, 2016 at 13:41
22

This works, but it will remove the title of the previous item, even if you pop back to it:

self.navigationController.navigationBar.topItem.title = @"";

Just set this property on viewDidLoad of the pushed View Controller.

4
  • 17
    This will remove the title of the previous item, even if you pop back to it. Not very good :(
    – Antzi
    Nov 27, 2013 at 10:12
  • I set the title of the pushing VC on viewWillAppear so it is always set properly. Nov 27, 2013 at 11:47
  • @GutoAraujo It works but the title re-appear with 1 or 2 secs delay witch makes UX not that good.
    – fuiiii
    Jul 19, 2014 at 23:15
  • In xCode8 -> ios10.X this seems to be the only way to address the issue
    – LucioB
    Feb 8, 2017 at 10:52
21

EDIT: 2014-04-09: As I gained reputations, I feel sorry because I don't use this trick any more. I recommend Kyle's answer. Also notice that the self of self.navigationItem.backBarButtonItem isn't the view controller the back button is displayed, but the previous view controller to be went back.

If you don't need to have title text for the previous view controller, just fill the title with a blank string;

self.navigationItem.title = @"";
[self.navigationController pushViewController:viewController animated:YES];

This will prevent showing "back" with chevron on the pushed view controller.

EDIT: Even you use non-blank title text, setting the title of the previous view controller in viewWillAppear: works except the title can flicker in a blink when view controller popped. I think "The twitter app" seems to do more subtle hack to avoid the flicker.

2
  • Only problem I had here was that when i hit the navigation bar to go back the title on the previous view becomes blank. Any way around that?
    – Alioo
    Oct 10, 2013 at 2:43
  • @Alioo Did you try what I mentioned in the "EDIT" line?
    – hiroshi
    Oct 10, 2013 at 12:09
13

This is how I do it and the simplest, works and most clear way to do it.

This works if embed on Navigation Controller

Swift 3

In viewDidLoad I add this to the View Controller you want the back button to be just arrow.

if let topItem = self.navigationController?.navigationBar.topItem {
   topItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
}

The difference of this to @Kyle Begeman's answer is that you call this on the view controller that you want the back button to be just arrow, not on the pushing stack view controller.

7

You don't have access to the navigation backButtonItem with the way you want, you need to create your own back button like below:

- (void)loadView
{
    [super loadView];
    UIButton *backButton = [[UIButton alloc] initWithFrame: CGRectMake(0, 0, 44.0f, 30.0f)];
    [backButton setImage:[UIImage imageNamed:@"back.png"]  forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(popVC) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
}

And off course:

- (void) popVC{
  [self.navigationController popViewControllerAnimated:YES];
}
4
  • then we lost the nice fade out animation happened on the back button
    – Kiddo
    Sep 18, 2013 at 11:12
  • 3
    You need a mask for smooth transitions. "* If you want to use a custom image to replace the default chevron, you also need to create a custom mask image. iOS 7 uses the mask to make the previous screen’s title appear to emerge from—or disappear into—the chevron during navigation transitions."
    – user
    Sep 22, 2013 at 3:25
  • 3
    @null you will lose the side-to-side swipe gesture of iOS 7! Oct 31, 2013 at 1:50
  • @user I get the custom image but the tint colour is blue by default. How can I get no tint added? thanks Oct 31, 2013 at 4:08
7

Target: customizing all back button on UINavigationBar to an white icon

Steps: 1. in "didFinishLaunchingWithOptions" method of AppDelete:

UIImage *backBtnIcon = [UIImage imageNamed:@"navBackBtn"];


if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
    [UINavigationBar appearance].tintColor = [UIColor whiteColor];
    [UINavigationBar appearance].backIndicatorImage = backBtnIcon;
    [UINavigationBar appearance].backIndicatorTransitionMaskImage = backBtnIcon;
}else{

    UIImage *backButtonImage = [backBtnIcon resizableImageWithCapInsets:UIEdgeInsetsMake(0, backBtnIcon.size.width - 1, 0, 0)];
    [[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage  forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -backButtonImage.size.height*2) forBarMetrics:UIBarMetricsDefault];
}

2.in the viewDidLoad method of the common super ViewController class:

 if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
        UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@""
                                                                     style:UIBarButtonItemStylePlain
                                                                    target:nil
                                                                    action:nil];
        [self.navigationItem setBackBarButtonItem:backItem];
    }else{
        //do nothing
    }
1
  • This shows a warning "Implicit version of SYSTEM_VESION_..." is invalid in C99. Aug 6, 2014 at 7:10
7

SWIFT 4

For those looking to create custom back buttons as well as have their title removed please use the following piece of code within the view controller that's pushing the new one:

self.navigationController?.navigationBar.backIndicatorImage = UIImage(named: "close")
self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "close")
self.navigationItem?.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)

For a more universal use, do the following:

  1. Create a universal function as follows:

    func addCustomizedBackBtn(navigationController: UINavigationController?, navigationItem: UINavigationItem?) {
        navigationController?.navigationBar.backIndicatorImage = UIImage(named: "close")
        navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "close")
        navigationItem?.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
    }
    
  2. Then use it in the view controllers as follows:

    addCustomizedBackBtn(navigationController: self.navigationController, navigationItem: self.navigationItem)
    
6

Simple hack from iOS6 works on iOS7 too:

[UIBarButtonItem.appearance setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault];

Edit: Don't use this hack. See comment for details.

3
  • 6
    Don't use this hack. There is a bug in Apple's code on 64 bit devices that will prevent modal views from appearing when you make a bar button title offset. More details. Oct 23, 2013 at 8:57
  • Well there were only problems on device, not simulator. Feb 12, 2016 at 4:54
  • This hack no longer works when built with Xcode 9 / iOS 11. The "<" will appear too low and you'll see broken constraints when run in the debugger.
    – T'Pol
    Oct 1, 2017 at 22:14
3

you can use this. This works perfectly for me by just adding a UIButton as a custumview for the UIBarButtonItem.

Try the Below Code

    self.navigationItem.leftBarButtonItem=[self backButton];


- (UIBarButtonItem *)backButton
{
    UIImage *image = [UIImage imageNamed:@"back-btn.png"];
    CGRect buttonFrame = CGRectMake(0, 0, image.size.width, image.size.height);

    UIButton *button = [[UIButton alloc] initWithFrame:buttonFrame];
    [button addTarget:self action:@selector(backButtonPressed) forControlEvents:UIControlEventTouchUpInside];
    [button setImage:image forState:UIControlStateNormal];

    UIBarButtonItem *item= [[UIBarButtonItem alloc] initWithCustomView:button];

    return item;
}
1
  • 3
    however, this will disable swipe back gesture in iOS 7
    – user102008
    Mar 15, 2014 at 0:58
3

Create a UILabel with the title you want for your root view controller and assign it to the view controller's navigationItem.titleView.

Now set the title to an empty string and the next view controller you push will have a back button without text.

self.navigationItem.titleView = titleLabel; //Assuming you've created titleLabel above
self.title = @"";
3
 // add left bar button item

try this code:

- (void)viewDidLoad
{ 
    [super viewDidLoad];

   UIImage* image_back = [UIImage imageNamed:@"your_leftarrowImage.png"];
    CGRect backframe = CGRectMake(250, 9, 15,21);
    UIButton *backbutton = [[UIButton alloc] initWithFrame:backframe];
    [backbutton setBackgroundImage:image_back forState:UIControlStateNormal];
    [backbutton addTarget:self action:@selector(Btn_back:)
         forControlEvents:UIControlEventTouchUpInside];
    [backbutton setShowsTouchWhenHighlighted:YES];
    UIBarButtonItem *backbarbutton =[[UIBarButtonItem alloc] initWithCustomView:backbutton];
    self.navigationItem.leftBarButtonItem=backbarbutton;
    [backbutton release];

}
-(IBAction)Btn_back:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];

}
3

All the answers do not solve the issue. It is not acceptable to set back button title in every view controller and adding offset to the title still makes next View Controller title shift to the right.

Here is the method using method swizzling, just create new extension to UINavigationItem

import UIKit

extension UINavigationItem {
    public override class func initialize() {

    struct Static {
        static var token: dispatch_once_t = 0
    }

    // make sure this isn't a subclass
    if self !== UINavigationItem.self {
        return
    }

    dispatch_once(&Static.token) {
        let originalSelector = Selector("backBarButtonItem")
        let swizzledSelector = #selector(UINavigationItem.noTitleBackBarButtonItem)

        let originalMethod = class_getInstanceMethod(self, originalSelector)
        let swizzledMethod = class_getInstanceMethod(self, swizzledSelector)

        let didAddMethod = class_addMethod(self, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod))

        if didAddMethod {
            class_replaceMethod(self, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod))
        } else {
            method_exchangeImplementations(originalMethod, swizzledMethod)
        }
    }
}

// MARK: - Method Swizzling

struct AssociatedKeys {
    static var ArrowBackButtonKey = "noTitleArrowBackButtonKey"
}

func noTitleBackBarButtonItem() -> UIBarButtonItem? {
    if let item = self.noTitleBackBarButtonItem() {
        return item
    }

    if let item = objc_getAssociatedObject(self, &AssociatedKeys.ArrowBackButtonKey) as? UIBarButtonItem {
        return item
    } else {
        let newItem = UIBarButtonItem(title: " ", style: UIBarButtonItemStyle.Plain, target: nil, action: nil)
        objc_setAssociatedObject(self, &AssociatedKeys.ArrowBackButtonKey, newItem as UIBarButtonItem?, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
        return newItem
    }
}
}
3
  • Set back button to the word back, works great: self.navigationItem.backBarButtonItem.title = @"Back";
    – Mike Zriel
    May 2, 2016 at 11:22
  • What do you mean mate? The question was about removing text from back button? May 7, 2016 at 8:35
  • 1
    Lots of App and Apple own Apps say "< Back", so it is good to stick to standard. BigTakeAway and JustEat.
    – Mike Zriel
    May 7, 2016 at 20:53
2

I applied the following code in viewDidLoad and it works:

  // this will set the back button title
self.navigationController.navigationBar.topItem.title = @"Test";

 // this line set the back button and default icon color  

//[[self.navigationController.navigationBar.subviews lastObject] setTintColor:[UIColor blackColor]];

this line change the back default icon to your custom icon
[[self.navigationController.navigationBar.subviews lastObject] setTintColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"menuicon"]]];

Just to update I use Vector Icon

2

You can subclass UINavigationController, set itself as the delegate, and set the backBarButtonItem in the delegate method navigationController:willShowViewController:animated:

@interface Custom_NavigationController : UINavigationController <UINavigationControllerDelegate>

@end

@implementation Custom_NavigationController

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.delegate = self;
}

#pragma mark - UINavigationControllerDelegate

- (void)navigationController:(UINavigationController *)navigationController     willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    viewController.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
}

@end
0
2

Set back title empty

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@""  style:UIBarButtonItemStyleDone target:self action:@selector(handleBack:)];
[backButton setTintColor:Color_WHITE];
[self.navigationItem setBackBarButtonItem:backButton];

Change back image

 UIImage *backImg = [[UIImage imageNamed:@"ic_back_white"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[UINavigationBar appearance].backIndicatorImage = backImg;
[UINavigationBar appearance].backIndicatorTransitionMaskImage = backImg;
2

Check this answer

How to change the UINavigationController back button name?

set title text to string with one blank space as below

title = " "

Don't have enough reputation to add comments :)

1

I have been using this solution since iOS 5 or so without any problems. I made a utility function that I call in my view controllers. You need to do it either in viewDidLoad or any point after that.

void updateBackButtonTextForViewController(UIViewController *viewController, NSString *text)
{
    if(! viewController.navigationItem.backBarButtonItem)
    {
        viewController.navigationItem.backBarButtonItem =
        [[UIBarButtonItem alloc] initWithTitle:text
                                         style:UIBarButtonItemStylePlain
                                        target:nil action:nil];
    }
    else
    {
        viewController.navigationItem.backBarButtonItem.title = text;
    }
}

In some cases the navigation item may already exist, in other cases it needs to be created. This accounts for both of those cases without messing with the navigation item title. It allows you to remove the title by simply passing in @"".

1
  • 1
    This is the correct answer. No tricks. This is just using the iOS API the way it was meant to be used, to set the title. Set it to @"" to remove the title (tested and works fine).
    – n13
    Feb 11, 2015 at 8:35
1

The only way that worked for me was:

navigationController?.navigationBar.backItem?.title = ""

UPDATE:

When I changed the segue animation flag to true (It was false before), the only way that worked for me was:

navigationController?.navigationBar.topItem?.title = ""
1

If you have two ViewController(FirstVC, SecondVC) Embed in Navigation Controller, and you want there is only back arrow in SecondVC.

You can try this In FirstVC's ViewDidLoad

override func viewDidLoad() {
    super.viewDidLoad()
    self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .Plain, target: nil, action: nil)
}

Then when you push into SecondVC, you'll see the there is only back arrow

1

If you set the tintColor Of NavigationBar,add a custom back button image without title that tint color will reflect the image color. Please follow this apple documentaion link.

https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/UIKitUICatalog/index.html#//apple_ref/doc/uid/TP40012857-UIView-SW7

UINavigationItem *navItem = [[UINavigationItem alloc] init];
   navBar.tintColor = self.tintColor;

   UIImage *myImage = [UIImage imageNamed:@"left_arrow.png"];
     myImage = [myImage              imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];

     UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithImage:myImage style:UIBarButtonItemStylePlain target:self action:@selector(cancelButtonFunction:)];
     navItem.leftBarButtonItem = leftButton;

    navBar.items = @[ navItem ];
1
  1. Add new UIBarButtonItem to UINavigationItem to left
  2. Change UIBarButtonItem how to want use
  3. Now, click UINavigationItem and swipe barBackButtonItem from outlets to left UIBarButtonItem

enter image description here

1

I'm written an extension to make this easier:

extension UIViewController {

    /// Convenience for setting the back button, which will be used on any view controller that this one pushes onto the stack
    @objc var backButtonTitle: String? {
        get {
            return navigationItem.backBarButtonItem?.title
        }
        set {
            if let existingBackBarButtonItem = navigationItem.backBarButtonItem {
                existingBackBarButtonItem.title = newValue
            }
            else {
                let newNavigationItem = UIBarButtonItem(title: newValue, style:.plain, target: nil, action: nil)
                navigationItem.backBarButtonItem = newNavigationItem
            }
        }
    }

}
1

You can change the title to @"" of the current ViewController on viewWillDisappear, and when it's about to show again re-set the title to whatever it was before.

-(void) viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.title = @"Previous Title";
}

-(void) viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    self.title = @"";
}
1
  • Change backItem.title = "" to using topItem.title = ""
  • Setting navigationItem.hidesBackButton = true & navigationItem.leftBarButtonItem will lose the back gesture
  • Remember we have to create 2 instances of the back image

My solution will change the image & keep the back gesture:

navigationController?.navigationBar.backIndicatorImage = UIImage(named: "back")
navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "back")
navigationController?.navigationBar.topItem?.title = ""
0

In the prepareForSegue: method of your first ViewController you set that views title to @"", so when the next view is pushed it will display the previous ViewController title which will be @"".

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    self.navigationItem.title = @" ";
}

The only problem with this is that when you hit the back button your previous view won't have a title, so you may add it again on viewWillAppear:

-(void)viewWillAppear:(BOOL)animated{
   self.navigationItem.title = @"First View Title";
}

I don't like very much this solution but it works and i didn't find other way to do it.

4
  • See my answer for the correct solution without messing with the navigation item title.
    – Dima
    Nov 6, 2013 at 20:30
  • Does your solution keeps the iOS7 back arrow? I tried something similar but it removed the arrow. Nov 7, 2013 at 17:10
  • It keeps the back arrow in iOS 7, yes. In iOS 6 passing in a blank(0 length) string will also remove the button completely though, so this doing this is only really good for iOS 7.
    – Dima
    Nov 8, 2013 at 4:27
  • There is a very simple solution. See if my answer works for you. Nov 9, 2013 at 0:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.