Change UINavigationBar back button title

44,217

Solution 1

Do this in the parent view controller not in the child

Swift

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

Objetive-C

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

Solution 2

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

Solution 3

If you are using storyboard you can select the navigation item in the parent view controller and set the button text you want in 'Back Button' field. Remember to set this in the parent view controller, not in the child that is pushed.

enter image description here

Solution 4

Try this hope it will be work

UIBarButtonItem *btn = 
        [[UIBarButtonItem alloc] initWithTitle:@"New Title" 
                                         style:UIBarButtonItemStyleBordered 
                                        target:nil 
                                        action:nil];
[[self navigationItem] setBackBarButtonItem:btn];

Solution 5

Back Button With Back Arrow

Objective-C

self.navigationController.navigationBar.topItem.backBarButtonItem = 
[[UIBarButtonItem alloc] initWithTitle:@"Title" style:UIBarButtonItemStylePlain
target:nil action:nil];

Swift

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

Normal Button Without Back Arrow

Objective-C

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

Swift

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

Bold Button Without Back Arrow

Objective-C

self.navigationItem.leftBarButtonItem = 
[[UIBarButtonItem alloc] initWithTitle:@"Title" 
style:UIBarButtonItemStyleDone target:nil action:nil];

Swift

self.navigationItem.leftBarButtonItem = UIBarButtonItem(title:"Title", 
style:.done, target:nil, action:nil)
Share:
44,217
S S
Author by

S S

Updated on September 24, 2020

Comments

  • S S
    S S over 3 years

    In my application I want to use 'Back' text as back button title for every viewcontroller. I have read so many posts on stackoverflow but got nothing.

    I don't want to set leftbarbuttonitem.

    Can anyone help me on this simple task.

    Thanks,

  • Gajendra Rawat
    Gajendra Rawat about 10 years
    add this line in view did load method from where you are switching next viewcontroller. like you are going to detailview controller(having back button) from master view controller then add it in masterview controller viewdidload method @SeemaSharma
  • Hamid Pourjam
    Hamid Pourjam over 8 years
    While this code may answer the question, it is better to explain what it does and add some references to it.
  • sheetal
    sheetal about 8 years
    Awesome fix... Thanks
  • Mathias Claassen
    Mathias Claassen about 8 years
    In my case navigationController?.navigationBar.backItem?.title = "" for back button
  • rustylepord
    rustylepord almost 8 years
    The problem with this approach would be , lets say you have a home view controller with the title "Home" , Then you navigate to the second view controller which has the title "Child" , when you apply this , it will change the back button title , however when you go back, it will change the home screen title back button title . ;) unless you don't set it explicitly again .
  • rustylepord
    rustylepord almost 8 years
    Tested and worlds well iOS 9.3.2
  • Lucas
    Lucas over 6 years
    navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil) in Swift
  • Sergiob
    Sergiob about 6 years
    This is a much better solution
  • Radames E. Hernandez
    Radames E. Hernandez over 5 years
    Thank you so much! this is so helpful for me
  • user25
    user25 about 5 years
    nothing changes, I've tried viewDidLoad and viewWillAppear
  • user25
    user25 about 5 years
    it changes tittle in the middle of bar not back button's title
  • user25
    user25 about 5 years
    it changes tittle in the middle of bar not back button's title
  • user25
    user25 about 5 years
    It doesn't work. Where do you call it? I tried viewDidLoad and viewWillAppear but nothing happens when it calls self.navigationController?.navigationBar.backItem?.title = "test"
  • andrew54068
    andrew54068 about 4 years
    have to add code above in previous view controller.
  • Gonçalo Gaspar
    Gonçalo Gaspar over 3 years
    Thank you this solved a long time issue. Only one that worked.