How to Change Back Button Title on Navigation Controller in Swift3

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 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];

Change back button of navigation controller

use this self.navigationItem.leftBarButtonItem = backButton

Change color and back button title of Navigation Bar from Swift 3 code

try

    self.navigationController?.navigationBar.tintColor = UIColor.white

How to change the Back button color in a DetailViewController?

I was able to change it with:

self.navigationController?.navigationBar.tintColor = UIColor.white

Hope this works for you!

Edit:

Once you create the project, you'll see the following in your storyboard:

Sample Image

I changed it to following:

Sample Image

Which gave me the following output:

Sample Image

And following is my code for viewDidLoad() in DetailViewController:

override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.navigationBar.tintColor = UIColor.red
// Do any additional setup after loading the view, typically from a nib.
configureView()
}

Hope this makes it clear enough now.

How to change the UINavigationController back button name?

In viewWillAppear write this

self.navigationItem.title = @"List View";

And in ViewWilldisapper write this

self.navigationItem.title = @"Back";

It works without story boards.



Related Topics



Leave a reply



Submit