How to change the title of the back button of the navigation bar

1

I would like to change the title of the back button of the navigation bar, change from "

I tried the following but did not succeed

        self.navigationController?.navigationItem.backBarButtonItem?.title = "Voltar"
    
asked by anonymous 20.08.2016 / 06:55

3 answers

2

You will probably need to create an object of UIBarButtonItem .

Try this:

Swift:

   let backButton = UIBarButtonItem(title: "< Back", style: UIBarButtonItemStyle.Plain, target: self, action: "goBack")
   navigationItem.leftBarButtonItem = backButton

Objective C:

    UIBarButtonItem *barBtnItem = [[UIBarButtonItem alloc]initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:self action:@selector(pop)];
    self.navigationItem.backBarButtonItem = barBtnItem;
    [barBtnItem release];

Another way you can try is that because the back button belongs to the previous ViewController, you can try to modify it before pushing.

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    let backItem = UIBarButtonItem()
    backItem.title = "Something Else"
    navigationItem.backBarButtonItem = backItem // This will show in the next view controller being pushed
}
    
22.08.2016 / 16:15
2

You can do this through the interface.

On the storyboard click on the screen you want, then on the view controller tab.

Ontherightsideoftheproperties,lookforthebackbuttonandyoucantypethedesiredtext.

OryoucanaddbycommandinviewDidLoad.

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

    
30.08.2016 / 15:06
0

Why do this in all Views if you can do it once?

To do this, just change the project settings:

  • In your project, open the "Supporting files" folder;
  • Edit the file "info.plist";
  • Expand the "Localizations" item;
  • Click the small "+" button and add "Portuguese";
  • Save the file.

After that, just check that your device / emulator is configured in the Portuguese language.

    
18.09.2018 / 21:06