I tried all options to change back button color for hours. But had no success and decided to open up source and see what the heck is going on there :) Here is the code we have inside NavigationController.swift which is missing a line:
item.backButton.tintColor = navigationBar.tintColor
public func navigationBar(_ navigationBar: UINavigationBar, shouldPush item: UINavigationItem) -> Bool {
if let v = navigationBar as? NavigationBar {
item.backButton.addTarget(self, action: #selector(handleBackButton), for: .touchUpInside)
item.backButton.image = v.backButtonImage
item.backButton.tintColor = navigationBar.tintColor
item.leftViews.insert(item.backButton, at: 0)
v.layoutNavigationItem(item: item)
}
return true
}
Thanks for this awsome library 馃憤 馃
Hey :) Thank you! To change the color of the backButton, you can use the navigationItem.backButton.tintColor property for the view controller you want to change it for. Take a look at the sample NavigationController project line #47.
Please reopen or create a new issue if you need any further help :)
I thought I tried to set navigationItem.backButton.tintColor 馃 but obviously didn't
Did you set it in the correct view controller? Take a loot at that sample. That should help you out :)
@danieldahan Well, actually I tried to set it globally, in AppNavigationController. I think there should be something like default back button color in order to set it once instead of setting color in every ViewController.
I agree @OrkhanAlikhanov :) I will make this a feature request and include it in Material 2.5.
Please, do not forgot pulse color :)
is it possible to change the tintColor with an extension of NavigationItem?
Hey @PetresS Not at the current moment, because the property is not open. I made a switch now, which will make its way to the next release.
@OrkhanAlikhanov I am closing this issue, as I have a feature request to allow for theming, which will handle this. As well, this fell behind my current schedule of features, and I have to re-prioritize it. Sorry for any delays.
Hey @OrkhanAlikhanov You can do this to set the global configuration of the backButton:
class AppNavigationController: NavigationController {
override func prepare() {
super.prepare()
guard let v = navigationBar as? NavigationBar else {
return
}
v.backButtonImage = Icon.arrowBack
}
}
@danieldahan I do that of course, my request was about the UINavigationItem.backButton.tintColor globally...
Ah sorry, I was read this incorrectly, well then that will need to be handled through theming. Thank you for the clarification :)
So again, how can we change tintColor of the backButton in a global level? I don't want to do that in every view controller that I push.
I don't want to change the sources either, to insert just one line:
item.backButton.tintColor = navigationBar.tintColor
Shouldn't the backButton.tint Colorbe equal to navigationBar.tintColor by default? I think it is the default behavior in UINavigationController that UIKit offers.
By the way, what I am discussing here is also applying to navigationItem.titleLabel.textColor.
You make a great point here, and there is a feature request to start allowing global color configurations. Maybe you can help me do this by outlining the details we should cover and we can make the change for everyones benefit. What do you think?
Let's move the discussion to the that feature request. #292