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:
I changed it to following:
Which gave me the following output:
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
How to Properly Use Queryorderedbyvalue
What Is the Correct Date.Format for Mmm Dd, Yyyy Hh:Mm:Ss A? and How Convert to Dd-Mm-Yyyy Hh:Ii
What Is the Use of "Static" Keyword If "Let" Keyword Used to Define Constants/Immutables in Swift
Does Swift Implement Tail Call Optimization? and in Mutual Recursion Case
Is Force Cast Really Bad and Should Always Avoid It
Uitextview Highlight All Matches Using Swift
How to Specify That a Non-Generic Swift Type Should Comply to a Protocol
Load Image from iOS 8 Framework
Embedding Videos in a Tableview Cell
Swift. Could Not Build Objective-C Module 'Alamofire'
Isn't There an How to Pinch to Zoom in an Image in Swiftui
Swift: Testing Against Optional Value in Switch Case
Is There a Difference Between Swift 2.0 Protocol Extensions and Java/C# Abstract Classes
How to Check Is a String or Number