How to remove all navigationbar back button title

后端 未结 30 3400
后悔当初
后悔当初 2020-12-12 15:42

When I push a UIViewController, it has some title in back button at new UIViewController, if the title has a lot of text, It does not look good in

30条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-12 16:04

    Adding a second answer here as my first only partially works. This method is less elegant in the fact that it requires calling a method in each view in the application, however it works without any side-effects.

    So firstly, create a UIViewController extension class with a function to remove back button text and add a custom back button:

    extension UIViewController {
    
    func setBackButton() {
        navigationController?.navigationBar.backIndicatorImage = R.image.backArrow()
        navigationController?.navigationBar.backIndicatorTransitionMaskImage = R.image.backArrow()
        navigationItem.backBarButtonItem = UIBarButtonItem(title: " ", style: .plain, target: nil, action: nil)
    }
    

    Secondly, we can simply call out to this function in the viewDidLoad of each view controller you need it in.

提交回复
热议问题