如何删除后退按钮的文本。

当前返回按钮:

<返回

需要的后退按钮:

< 其他任何东西

这些都没有奏效:

self.navigationItem.backBarButtonItem?.title = "Back"
self.backItem?.title = ""
self.navigationController?.navigationBar.backItem?.title = ""
self.navigationItem.backBarButtonItem?.title = ""
self.navigationController?.navigationItem.backBarButtonItem?.title="Back"
self.navigationController?.navigationBar.backItem?.title = ""
self.navigationController?.navigationItem.backBarButtonItem?.title

当前回答

Swift 4.2

let backItem = UIBarButtonItem()
backItem.title = ""
navigationItem.backBarButtonItem = backItem

其他回答

在呈现控制器的viewDidLoad方法中添加:

// hide navigation bar title in the next controller
let backButton = UIBarButtonItem(title: "", style:.Plain, target: nil, action: nil)
navigationItem.backBarButtonItem = backButton

back按钮属于前一个视图控制器,而不是当前显示在屏幕上的那个。 要修改后退按钮,你应该在按之前更新它,添加viewdidload:

斯威夫特4:

self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: self, action: nil)

这对我很管用。斯威夫特5

navigationItem.backButtonTitle = ""

如果你正在为视图控制器使用xib文件,那么在你的视图控制器类中这样做。

class AboutUsViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    edgesForExtendedLayout = []
    setUpNavBar()
}

func setUpNavBar(){
    //For title in navigation bar
    self.navigationController?.view.backgroundColor = UIColor.white
    self.navigationController?.view.tintColor = UIColor.orange
    self.navigationItem.title = "About Us"

    //For back button in navigation bar
    let backButton = UIBarButtonItem()
    backButton.title = "Back"
    self.navigationController?.navigationBar.topItem?.backBarButtonItem = backButton
}

}

结果将是:

你可以在故事板中修改NavigationItem

在后退按钮中添加一个空格并按Enter。

注意:在之前的VC中这样做。