How to Change the Title of the "Back" Button on a Navigation Bar

How do I change the title of the back button on a Navigation Bar

This should be placed in the method that calls the ViewController titled "NewTitle".
Right before the push or popViewController statement.

UIBarButtonItem *newBackButton = 
[[UIBarButtonItem alloc] initWithTitle:@"NewTitle"
style:UIBarButtonItemStyleBordered
target:nil
action:nil];
[[self navigationItem] setBackBarButtonItem:newBackButton];
[newBackButton release];

How to set back button text in Swift

The back button belongs to the previous view controller, not the one currently presented on screen.

To modify the back button you should update it before pushing, on the view controller that initiated the segue:

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
}

Swift 3, 4 & 5:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let backItem = UIBarButtonItem()
backItem.title = "Something Else"
navigationItem.backBarButtonItem = backItem // This will show in the next view controller being pushed
}

OR

// in your viewDidLoad or viewWillAppear
navigationItem.backBarButtonItem = UIBarButtonItem(
title: "Something Else", style: .plain, target: nil, action: nil)

How to change back button text in Navigation item to picture in xcode

Add below code in viewDidLoad of viewController where you want to change back button title:

 let backButton = UIBarButtonItem()
backButton.title = ""
self.navigationController?.navigationBar.topItem?.backBarButtonItem = backButton

Sample Image

[ios]change title of back button on navigation bar

Finally solved this by assigning a delegate to UINavigation Controller's interactivePopGestureRecognizer.
And it must be executed in or after viewWillAppear, in this particular order

self.navigationItem.backBarButtonItem = backButton;
self.navigationController.interactivePopGestureRecognizer.delegate = self;

Once I did that I can change the title of backBarButtonItem however I want.

Got my answer from

http://blog.csdn.net/zhaoxy_thu/article/details/15811189

I don't know how it works, I don't know why simply assigning a delegate to a swipe gesture recognizer enables the title of back button to be customizable, I simply followed the instructions in this magical blog post. Thanks zhaoxy_thu for making this work.

How to change back button color in nav bar?

Use Below To Change Back Button Color:

navigationController?.navigationBar.tintColor = UIColor.red

To Change Title Color of The Navigation Bar Use:

navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.red]

How to change UINavigationBar Title and Back Button Colour from Storyboard?

What is the best way of changing colors for Title and Back button of UINavigationBar from Storyboard?

The color of the title is an attribute of the navigation bar, so select the navigation controller's navigation bar:

navigation bar selection

and then look at the Attributes Inspector, where you can set the title color:

title color

The color of the Back button is controlled by the tint color. You can set the global tint color in the File Inspector for the storyboard:

global tint color

These settings should work fine if you want to set the title and tint color once for the whole app, but if you want different colors for different view controllers, then one way or another you're going to have to write some code. If that's something you need to do often, and you want to be able to set the colors in IB, you could consider writing your own UIViewController subclass from which all your view controllers are derived. Give that common controller class inspectable attributes for the colors you want to set, and of course add code that sets them appropriately. You'll probably want to use UIAppearance for that.

Bear in mind, though, that the reason that these colors aren't already attributes of UIViewController is that the colors are supposed to help give your app a consistent appearance; changing your app's color scheme from one scene won't be a favor to your users.



Related Topics



Leave a reply



Submit