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

Asked

Viewed 964 times

1

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

I tried this way but I did not succeed

        self.navigationController?.navigationItem.backBarButtonItem?.title = "Voltar"

  • If you change the previous view controller title, the button will use this title.

  • I hate the default navbar, what I always do is create a view from above and customize my navbar, and the default navbar I leave hidden.

3 answers

2


You will probably need to create an object 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 as the back button belongs to the previous Viewcontroller, you can try modifying it before you push.

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
}

2

You can do by the interface by the following mode.

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

inserir a descrição da imagem aqui

On the right side of the property, search back button and can type the desired text.

inserir a descrição da imagem aqui

Or you can add by command in viewDidLoad.

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

0

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

For this just change in the project settings:

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

inserir a descrição da imagem aqui

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.