How to remove all navigationbar back button title

后端 未结 30 3402
后悔当初
后悔当初 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:10

    You could create a subclass for all UIViewControllers you want this behavior for, and in the subclass's viewDidLoad:

    override func viewDidLoad() {
        super.viewDidLoad()
        self.navigationItem.backBarButtonItem = UIBarButtonItem(
            title: "", style: .plain, target: nil, action: nil)
    }
    

    This way, you can choose which controllers you want the behavior for, without duplicating code. I prefer my controllers to just say "Back", rather than the title of the previous controller, so I set that title here.

提交回复
热议问题