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
[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:
and then look at the Attributes Inspector, where you can set the 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:
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
Adjust Uilabel Height Depending on the Text
Can You Animate a Height Change on a Uitableviewcell When Selected
Check For Internet Connection With Swift
Nsnotificationcenter Addobserver in Swift
Converting String to Int With Swift
Undefined Symbols For Architecture Arm64
Ios 7 Status Bar Back to iOS 6 Default Style in Iphone App
Exc_Bad_Access Signal Received
Instantiate and Present a Viewcontroller in Swift
Fast and Lean Pdf Viewer For Iphone/Ipad/Ios - Tips and Hints
Applications Are Expected to Have a Root View Controller At the End of Application Launch
Status Bar and Navigation Bar Appear Over My View'S Bounds in iOS 7
How to Hide Keyboard When Using Swiftui
Handling Applicationdidbecomeactive - "How Can a View Controller Respond to the App Becoming Active"