I have a navigation controller for which I'd like to override the default back arrow image and text. Basically, instead of the < Back
, I'd like to hide the little <
arrow, and just show the Back
text. I've been able to replace the back arrow with another image, so I figured i'd just try to replace it with an image and then set the image to match the color of the background. How can I accomplish this?
In AppDelegate.swift I have this:
extension UINavigationItem{
override open func awakeFromNib() {
super.awakeFromNib()
let backItem = UIBarButtonItem()
backItem.title = ""
backItem.image = UIImage(named: "icons8_burger")
self.backBarButtonItem = backItem
}
}
In the viewDidLoad() for the controller that we are sent to when the button is clicked, I have this:
override func viewDidLoad() {
super.viewDidLoad()
let burger = UIImage(named: "icons8_burger")
navigationController?.navigationBar.backIndicatorImage = burger
navigationController?.navigationBar.backIndicatorTransitionMaskImage = burger
}
So, any ideas how I can accomplish this? I haven't found what I'm looking for thus far.
Any advice appreciated!
If you do ,
navigationController?.navigationBar.backIndicatorImage = nil
navigationController?.navigationBar.backIndicatorTransitionMaskImage = nil
or
navigationController?.navigationBar.backIndicatorImage = UIImage(named: "")
navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "")
Then by default iOS use <
as default image.
To remove this image you need to add blank transparent image. I used sample from here and google image reference is here
Now reduce the image pixel size to (1,1)
and add in your assets and use below code.
navigationController?.navigationBar.backIndicatorImage = UIImage(named: "Blank")
navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "Blank")
Here Blank is the same image name in my asset.