Remove text from Back button keeping the icon

前端 未结 29 2637
栀梦
栀梦 2020-11-28 23:26

I want to remove the text from the back button, but I want to keep the icon. I have tried

let backButton = UIBarButtonItem(title: \"\", style: UIBarButtonIt         


        
29条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-29 00:10

    The text of the back button depends on the title of the master view.

    The trick is to clear the title if the master view disappears and set it again if it is shown again:

    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
    
        // needed to clear the text in the back navigation:
        self.navigationItem.title = " "
    }
    
    override func viewWillAppear(_ animated: Bool) {
       
        super.viewWillAppear(animated)
        self.navigationItem.title = "My Title"
    }
    

提交回复
热议问题