Remove text from Back button keeping the icon

前端 未结 29 2634
栀梦
栀梦 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:07

    If you have a ViewControllerA and you want to navigate to the ViewControllerB, in the ViewControllerA, you should set the current navigationItem with a new UIBarButtonItem and the title to a string with blank space before push to another view controller:

    Set the title to a string with a blank space, you can't set nil or "" (empty string) because the default value is nil

    let backItem = UIBarButtonItem()
    backItem.title = " "
    navigationItem.backBarButtonItem = backItem
    let controllerB = ViewControllerB()
    navigationController?.pushViewController(controllerB, animated: true)
    

提交回复
热议问题