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

当前返回按钮:

<返回

需要的后退按钮:

< 其他任何东西

这些都没有奏效:

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

当前回答

后退按钮文本和彩色文本:

navigationController?.navigationBar.tintColor = .red
navigationController?.navigationBar.topItem?.backButtonTitle = "Hi"

其他回答

后退按钮文本取自父视图控制器的导航项标题。所以无论你在前一个视图控制器的导航项标题上设置了什么,都会显示在当前视图控制器的后退按钮文本上。 你可以把""作为导航项标题在父视图控制器的viewWillAppear方法中。

self.navigationItem.title = ""

另一种方法是

self.navigationController?.navigationBar.topItem?.title = ""

在当前视图控制器的viewWillAppear方法中。如果导航堆栈嵌套过多,这将导致一些其他问题。

后退按钮文本和彩色文本:

navigationController?.navigationBar.tintColor = .red
navigationController?.navigationBar.topItem?.backButtonTitle = "Hi"
override func viewWillAppear(_ animated: Bool) {

    self.tabBarController?.navigationItem.title = "Notes"

    let sendButton = UIBarButtonItem(title: "New", style: .plain, target: self, action: #selector(goToNoteEditorViewController))

    self.tabBarController?.navigationItem.rightBarButtonItem = sendButton
}

func goToNoteEditorViewController(){
   // action what you want
}

希望能有所帮助!!3 #迅速

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

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

back按钮属于前一个视图控制器,而不是当前显示在屏幕上的那个。 要修改返回按钮,你应该在按之前更新它,在启动segue的视图控制器上:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    let backItem = UIBarButtonItem()
    backItem.title = "Something Else"
    navigationItem.backBarButtonItem = backItem // This will show in the next view controller being pushed
}

Swift 3,4和5:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    let backItem = UIBarButtonItem()
    backItem.title = "Something Else"
    navigationItem.backBarButtonItem = backItem // This will show in the next view controller being pushed
}

OR

// in your viewDidLoad or viewWillAppear
navigationItem.backBarButtonItem = UIBarButtonItem(
    title: "Something Else", style: .plain, target: nil, action: nil)