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.
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 "" .
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With