Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UINavigationController "back button" custom text?

The "back button" of a UINavigationController by default shows the title of the last view in the stack. Is there a way to have custom text in the back button instead?

like image 703
Ali Shafai Avatar asked Sep 17 '09 22:09

Ali Shafai


People also ask

How do I change the back button text in Swift?

In view controller A, create a UIBarButtonItem with any title you want and set it to navigationItem. backBarButtonItem . This will set a back button title to "You back button title here". To make the title empty, just set the title to nil or an empty string "" .


2 Answers

From this link:

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

As Tyler said in the comments:

don't do this in the visible view controller, but in the view controller that you'd see if you hit the back button

like image 81
rein Avatar answered Oct 06 '22 14:10

rein


You can set the text in the Interface Builder:

Select the navigation item of the ViewController that the back button would return to:

enter image description here

In the utilities panel attribute inspector, enter your label for the Back Button:

enter image description here

I would prefer this approach over setting the title in code as in the accepted answer.

Also note, you need to do this in the view controller one level up the stack. In other words, don't do this in the visible view controller, but in the view controller that you'd see if you hit the back button.
--Tyler

like image 32
Petr Peller Avatar answered Oct 06 '22 14:10

Petr Peller