Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change text on a back button

By default the back button uses as a text on it a title of a viewcontroller. Can I change text on the back button without changing a title of a view controller? I need this because I have a view controller which title is too long to display and in this case I would like to display just "Back" as a caption for back button.

I tried the following which didn't work:

self.navigationItem.leftBarButtonItem.title = @"Back"; 

Thanks.

like image 884
Ilya Suzdalnitski Avatar asked May 07 '09 16:05

Ilya Suzdalnitski


People also ask

How do I change the back button title?

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 "" .

How do I customize the back button on my iPhone?

Check that you have the latest version of iOS on your iPhone 8 or later. Go to Settings > Accessibility > Touch, and tap Back Tap. Tap Double Tap or Triple Tap and choose an action. Double or triple tap on the back of your iPhone to trigger the action you set.

How do I change the text back button in Swift?

If you want to change the navigation bar back button item text, put this in viewDidLoad of the controller BEFORE the one where the back button shows, NOT on the view controller where the back button is visible. Save this answer.

How do I hide the back button name in react native?

We need to set false to the gesturesEnabled along with headerLeft to null . You can hide the back button using left:null , but for android devices it's still able to go back when the user presses the back button.


2 Answers

Try

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

I found that by looking at the backBarButtonItem docs in Apple's docs for UINavigationItem.

like image 93
Marc W Avatar answered Oct 16 '22 02:10

Marc W


Marc W's approach worked great once I figured out which controller to apply it to: the one being re-titled, not the one on top. So if this is the navigation stack:

(bottom)  ControllerA -> ControllerB  (top) 

...and you want to give a shorter title for ControllerA in the back-button displayed when ControllerB is on top, you apply the property change to ControllerA.

So it's more in the context of self.title, not like the other left/right-bar-button setters.

like image 20
Marco Avatar answered Oct 16 '22 01:10

Marco