I tried this code:
navigationController?.navigationItem.backBarButtonItem?.title = ""
but it does not work and did not change anything. How can I set backButton text to empty?
I tried this code for back button title. and it's work correctly
let barButton = UIBarButtonItem()
barButton.title = ""
self.navigationController?.navigationBar.topItem?.backBarButtonItem = barButton
self.navigationController!.navigationBar.topItem!.title = ""
You should use:
navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .Plain, target: nil, action: nil)
for see just < instead of < viewController
You have to change the previous controller's title, try doing so before the segue in the viewDidDisappear
To remove the backButtonItem's title, place this line of code in the viewDidLoad: of the View Controller that the backButtonItem is in:
navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .Plain,
target: nil, action: nil)
self.navigationItem.leftBarButtonItem=nil;
or
self.navigationItem.backBarButtonItem=nil;
Related
public override func viewDidLoad() {
super.viewDidLoad()
navigationItem.backBarButtonItem = .init(image: "back_icon".image, style: .plain, target: nil, action: nil)
}
For this above code, I got my back_icon image with the default back image
Any idea to remove the default back button at the same time preserving swipe edge to pop viewController.
You should be able to change the back button image globally by using
UINavigationBar.appearance().backIndicatorImage = UIImage(named: "arrow-back")
UINavigationBar.appearance().backIndicatorTransitionMaskImage = UIImage(named: "arrow-back")
And if you only want to change it in some places:
navigationController?.navigationBar.backIndicatorImage = UIImage(named: "arrow-back")
navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "arrow-back")
Removing an arrow at all would be as simple as
navigationController?.navigationBar.backIndicatorImage = UIImage()
navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage()
You can remove default back Button by following way:
navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
And manually add navigation items in left side using navigationitem.leftBarButtonItem.
Hope it helps!
I want to make my backBarButtonItem to be only < , without back. I have searched stackOverflow and found some solutions, but it stays < back.
I tried this in my pushed VC:
navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
and also this, in my AppDelegate:
navigationController.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
But none of two helped me. Anyone knows why?
This is how I push my ViewControllers:
let VC = XYZViewController()
self.navigationController?.pushViewController(VC, animated: true)
navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
Write this piece of code in the controller from which you are pushing to the next controller
I'm trying to remove the text "Back" from the navigation back button, leaving just the back chevron, but everything I'm trying is not working. For example if I add something like the following, obtained from previous answers to the same question, to viewDidLoad:
navigationItem.backBarButtonItem = UIBarButtonItem(title: "go away", style: .plain, target: nil, action: nil)
or
navigationController?.navigationBar.backBarButtonItem = UIBarButtonItem(title: "go away", style: .plain, target: nil, action: nil)
Then when the view appears it's still showing "< Back" in the navigation bar.
Here's what the views look like within captured within viewDidAppear.
Image:1
Try this code snippet hope it will help you
happy coding =)
override func viewDidLoad() {
DispatchQueue.main.async {
if let navBar = self.navigationController?.navigationBar {
navBar.backItem?.title = ""
}
}
}
You should create a left button and set the action to return to the rootViewController.
In viewDidLoad:
let leftButton = UIBarButtonItem(title: "<", style: .plain, target: self, action: #selector(back(_ :)))
self.navigationItem.leftBarButtonItem = leftButton
You are changing the wrong thing. You use this code here to change the title for the back button.
navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Back", style: .done, target: self, action: #selector(handleBack))
By doing this you need to add a selector for the button as well. Cause if you click the back button nothing will happen. This is how you would do that.
#objc private func handleBack() {
navigationController?.popViewController(animated: true)
}
Hope this helps.
Alternatively, from Interface Builder, you can set previous UIViewController's Back Button on Navigation Item to " " (not empty string, space):
Can someone clever explain me why this is happening?
I have a ViewController A and ViewController B where A does push() and B is on top.
Inside A I have created this code:
private lazy var backBarButton: UIBarButtonItem = {
let button = UIBarButtonItem(image: UIImage(named: "back"), style: .plain, target: nil, action: nil)
button.tintColor = .white
return button
}()
This gives me this crazy output :) It's like default iOS arrow + mine next to each other.
At least it does not have "Back" title which is also something that I need :)
When I change my code to something like that:
private lazy var backBarButton: UIBarButtonItem = {
let button = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
button.tintColor = .white
return button
}()
I've got arrow (and can modify it's tint), no title but it's not the same as my custom image.
Why is my custom image simply not replacing the system stock one?
First I would hide the default back button using
self.navigationController?.navigationItem.hidesBackButton = true
And then I can proceed and add a new custom back button on the left items
self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "back"), style: .plain, target: nil, action: nil)
you can set custom back navigation button by below code :
private lazy var backBarButton: UIBarButtonItem = {
let button = UIBarButtonItem(image: UIImage(named: "back"), style: .plain, target: nil, action: nil)
button.tintColor = .white
return button
}()
self.navigationController?.navigationItem.hidesBackButton = true
self.navigationItem.backBarButtonItem = backBarButton
Hi there I'm not able to change the navigation bar default back button's title
I've tried that :
self.navigationController?.navigationBar.backItem?.title="retour"
self.navigationController?.navigationItem.leftBarButtonItem?.title="retour"
self.navigationItem.backBarButtonItem?.title="retour"
self.navigationItem.leftBarButtonItem?.title="retour"
Set as leftBarButtonItem
var backBtn : UIBarButtonItem = UIBarButtonItem(title: "retour", style: UIBarButtonItemStyle.Plain, target: self, action: nil)
self.navigationItem.leftBarButtonItem = backBtn