238

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)];
Sahil Kapoor
  • 11,183
  • 13
  • 64
  • 87
Kiddo
  • 5,052
  • 6
  • 47
  • 69
  • 3
    You can use @hiroshi answer + navigation bar tintColor property to make chevron with custom color and without any titles – Dmitry Zhukov Sep 26 '13 at 09: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 01 '17 at 01:10

36 Answers36

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.

Zack
  • 1,585
  • 1
  • 18
  • 29
Kyle Begeman
  • 7,169
  • 9
  • 40
  • 58
  • 3
    I used this but the title comes and disappears in an animated fashion?? – user1010819 Nov 02 '13 at 04: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 06 '14 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? – Kyle Begeman Jan 07 '14 at 01: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! – Kyle Begeman Jan 07 '14 at 01:48
  • I've added [a little follow-up](http://stackoverflow.com/a/22584725/971055) on how to avoid copy-pasting this code everywhere :) – secondcitysaint Mar 22 '14 at 23:02
  • Great answer! Why the heck is it buried at the bottom of the page?? – Jason Moore Apr 04 '14 at 18:01
  • Thanks! Not sure why this is still not the answer? +1 for swift example :) – Michael Schinis Nov 22 '14 at 00:46
  • 3
    I feel like this needs an update, it just shows nothing right now, the arrow is not there by default? – Mathijs Segers Mar 28 '15 at 10:23
  • Is there a way you can change the image besides the text? – netwire May 02 '15 at 13:12
  • I am shocked this worked. And it keeps the arrow, and still pops the stack. It does also allow you to set another title; in my case I needed "BACK" globally. – Lee Probert Nov 29 '16 at 18:17
  • and also worth adding that I set this in the viewwillappear method of a super view controller that I use for all my others. – Lee Probert Nov 29 '16 at 18:18
  • @KyleBegeman The trick works for me but I am facing one issue. I am setting the accessibility identifier for the UIBarButtonItem for the previous view controller as you suggested. But it is not visible in accessibility inspector and appium too. – Mayank May 02 '21 at 08:57
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:

Thomás Pereira
  • 9,589
  • 2
  • 31
  • 34
  • Welcome to [so]. If you haven't already, take a look at what we're [about], and read some of the articles in the [help] 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] (if you still couldn't find an answer). Thanks, and good luck! Anyway, you can post your images now... :) – Qantas 94 Heavy Nov 30 '13 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 '14 at 20:42
  • Make sure you don't have "hidesBackButton" set to TRUE on the navigation item in ViewA – shim May 11 '14 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 '14 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 '14 at 01:10
  • Is it possible to set "back button" through programatically ? – Ajumal Apr 16 '16 at 14:26
  • @Aju Changing back button programatically: http://stackoverflow.com/a/19131107/3052059 – Thomás Pereira Apr 16 '16 at 15:37
  • For me it is enough to define it in the **destination view** controller on **iOS 11**. – kiecodes Jan 25 '18 at 00:29
76

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

Icon-Back@2x.png

Icon-Back@2x

Icon-Back@3x.png

Icon-Back@23x

aaannjjaa
  • 338
  • 3
  • 6
mt81
  • 3,288
  • 1
  • 26
  • 35
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!

Anibal Itriago
  • 1,051
  • 10
  • 13
  • 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 '13 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

Swaroop S
  • 490
  • 5
  • 11
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.

iwasrobbed
  • 46,496
  • 21
  • 150
  • 195
Guto Araujo
  • 3,824
  • 2
  • 21
  • 26
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
Community
  • 1
  • 1
secondcitysaint
  • 1,158
  • 12
  • 20
  • 1
    I upvoted but then decided to use a simpler hack instead -- `[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-1000, -1000) forBarMetrics:UIBarMetricsDefault];` ([source](http://www.fousa.be/blog/empty-back-button-in-ios-7)) -- might be a bit less elegant, but swizzling felt like overkill – dmur Mar 31 '14 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](https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/CustomizingExistingClasses/CustomizingExistingClasses.html) you should take advantage of this when possible. – zmonteca Mar 10 '15 at 01: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](https://blog.newrelic.com/2014/04/16/right-way-to-swizzle/) and this [NSHipster swizzling guide](http://nshipster.com/method-swizzling/) – Alessandro Orrù Jan 13 '16 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. – secondcitysaint Jan 13 '16 at 13:41
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.

hiroshi
  • 6,871
  • 3
  • 46
  • 59
  • 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 '13 at 02:43
  • @Alioo Did you try what I mentioned in the "EDIT" line? – hiroshi Oct 10 '13 at 12:09
12

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.

r_19
  • 1,858
  • 1
  • 20
  • 16
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];
}
Tarek Hallak
  • 18,422
  • 7
  • 59
  • 68
  • then we lost the nice fade out animation happened on the back button – Kiddo Sep 18 '13 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 '13 at 03:25
  • 3
    @null you will lose the side-to-side swipe gesture of iOS 7! – Mazen Kasser Oct 31 '13 at 01:50
  • @user I get the custom image but the tint colour is blue by default. How can I get no tint added? thanks – Mazen Kasser Oct 31 '13 at 04: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
    }
theftprevention
  • 5,083
  • 3
  • 18
  • 31
Jagie
  • 2,190
  • 3
  • 27
  • 25
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.

zh.
  • 1,533
  • 1
  • 14
  • 18
  • 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](http://stackoverflow.com/a/19119388/674741). – zh. Oct 23 '13 at 08:57
  • Well there were only problems on device, not simulator. – zh. Feb 12 '16 at 04: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 01 '17 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;
}
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 = @"";
rounak
  • 9,217
  • 3
  • 42
  • 59
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];

}
Paresh Hirpara
  • 487
  • 3
  • 10
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
    }
}
}
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
Nate Potter
  • 3,222
  • 2
  • 22
  • 24
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;
warriorg
  • 86
  • 1
  • 5
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 :)

Leojin
  • 31
  • 5
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 @"".

Dima
  • 23,484
  • 6
  • 56
  • 83
  • 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 '15 at 08: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 = ""
Siamaster
  • 941
  • 12
  • 19
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

Yu-Lin Wang
  • 131
  • 2
  • 5
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 ];
Nazish Ali
  • 320
  • 3
  • 16
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
            }
        }
    }

}
Mark Bridges
  • 8,228
  • 4
  • 50
  • 65
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 = @"";
}
WaleedAmmari
  • 510
  • 4
  • 10
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 = ""
Tai Le
  • 8,530
  • 5
  • 41
  • 34
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.

Alejandro Figueroa
  • 419
  • 1
  • 4
  • 14
  • See my answer for the correct solution without messing with the navigation item title. – Dima Nov 06 '13 at 20:30
  • Does your solution keeps the iOS7 back arrow? I tried something similar but it removed the arrow. – Alejandro Figueroa Nov 07 '13 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 08 '13 at 04:27
  • There is a very simple solution. See if my answer works for you. – Guto Araujo Nov 09 '13 at 00:07
0

To add to Thomas C's answer above, sometimes putting a single space doesn't work and you have to keep adding spaces.

empty bar button

You'll know you succeeded when you see "Bar Button Item - " under the "Navigation Item". That's in the Document Outline (Editor->Show Document Outline). Once you see the above picture, you can delete a few spaces and see if it still works.

Community
  • 1
  • 1
Rog182
  • 4,829
  • 1
  • 14
  • 4
0
- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self) {
        // Custom initialization
        self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];

    }
    return self; 
}

Just like Kyle Begeman does, you add the code above at your root view controller. All the sub view controller will be applied. Additionally, adding this in initWithCoder: method, you can apply the style for root view controllers in xib, storyboard or code based approaches.

Chris So
  • 711
  • 1
  • 11
  • 23
0
  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

ali ozkara
  • 5,425
  • 2
  • 27
  • 24
0

You may place that category in AppDelegate.m file. to removes text from all default back buttons in UINavigation. Only the arrow "<" or set custom image if you need.

Objective-c:

...

@end

@implementation UINavigationItem (Extension)

- (UIBarButtonItem *)backBarButtonItem {

    return [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
}

@end
Aleksandr B.
  • 505
  • 4
  • 6
0

Set back button item title as empty String.

[self.navigationController.navigationBar.backItem setTitle:@""];

  • 1
    this thing has already been highlighted in other answer as well, It doesn't bring something new or cover a new aspect for this question.! – mfaisalhyder Oct 27 '17 at 05:31
-1

This works a treat for both iOS6 and 7

Xamarin(C#) options

var buttonStyleItems = UIBarButtonItem.AppearanceWhenContainedIn(typeof(SettingsNavigationController));
buttonStyleItems.SetBackButtonTitlePositionAdjustment(new UIOffset(-1000, -1000), UIBarMetrics.Default);

Objective-C option

[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-1000, -1000) forBarMetrics:UIBarMetricsDefault];

Kodejack
  • 441
  • 4
  • 7
  • This unfortunately causes 64 bit compatibility issues if your app supports 32 bit devices. It is an Apple bug, but there is no workaround and it is not a viable solution. See my answer for a working approach. – Dima Nov 06 '13 at 20:32
  • The answer states that is works iOS6 and 7? Support for future releases cannot be guarantee.... – Kodejack Oct 13 '17 at 19:49
-1

This did the trick for me

[[UIBarButtonItem appearance] 
setBackButtonTitlePositionAdjustment:UIOffsetMake(-1000, -1000) 
forBarMetrics:UIBarMetricsDefault];

All the best

Warrior
  • 39,156
  • 44
  • 139
  • 214