Hello StackOverflow community,
I have a rather curious case of a customized back button on my navigation controller's navigation bar disappearing on interaction.
Some additional information is that my code is not using Storyboard and I use UIKit - everything including the UI has been build programatically.
This is my set up:
I start with creating a custom UINavigationController subclass to abstract away all of my navigation controller related customizations
Within this subclass, I have this method that get's called to customized the appearance of my back button
private func customizeBackButton() {
let backImage = UIImage(named: "BackButton")?.withRenderingMode(.alwaysOriginal)
navigationBar.backIndicatorImage = backImage
navigationBar.backIndicatorTransitionMaskImage = backImage
UIBarButtonItem.appearance().setTitleTextAttributes([
NSAttributedString.Key.foregroundColor: UIColor.panoStoryYellow,
NSAttributedString.Key.font: UIFont(name: "Montserrat-SemiBold", size: 15)!
], for: .normal)
}
- The above customization, gives the following result which is what I desire with Gallery being the title of my previous screen
- When I tap towards the left most edge of the back button where the arrow is, the button works normally. However, if I tap on the label section of the back button, where the Gallery text is, the text disappears and keeps the user on the same screen.
When I tap on the back arrow after the label disappears, it works and takes me back to the previous screen, however, why would this disappearance occur ?
What have I tried I have tried many suggestions on stack overflow such as:
- making sure no line in my code hides the back button explicitly
- Checking that previous screen's title to an empty string at any point
I can confirm that these are not the issue as I have a valid title and never hide the back button.
Here are some resources I have checked before deciding that none of them work for my case and I asked the question on here:
UINavigationController Back Button not visible, but works
UINavigationController's back button disappears?
Navigation title disappears after use of custom back button
navigation title on previous screen disappear when back button pressed
Missing Navigation's or Back Button's Title When Push ViewControllers in Succession
Any ideas as to why this back button text disappears ?