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

当前返回按钮:

<返回

需要的后退按钮:

< 其他任何东西

这些都没有奏效:

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

当前回答

如果你正在为视图控制器使用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
}

}

结果将是:

其他回答

虽然这些答案解决了问题,但这可能是一些有用的

class MainNavigatioController: UINavigationController {

    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        // first
        let backItem = UIBarButtonItem()
        backItem.title = "رجوع"
        self.viewControllers.last?.navigationItem.backBarButtonItem = backItem
        // then
        super.pushViewController(viewController, animated: animated)

    }

}

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

navigationItem.backButtonTitle = ""

这应该可以工作:

override func viewDidLoad() {
    super.viewDidLoad()

    var button = UIBarButtonItem(title: "YourTitle", style: UIBarButtonItemStyle.Bordered, target: self, action: "goBack")
    self.navigationItem.backBarButtonItem = button

}

func goBack()
{
    self.navigationController?.popViewControllerAnimated(true)
}

虽然不建议这样做,因为这实际上取代了backButton,它也删除了后退箭头和滑动手势。

Swift 4.2

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

如果你正在从页面视图控制器页面推送一个视图控制器,你不能更新导航控制器的后退按钮标题。要解决这个问题,创建一个委托回到你的父视图控制器(你也可以遍历视图控制器层次结构回到父视图控制器)。

此外,后退按钮有字符限制。如果超过该字符限制,系统将默认为“返回”。它不会为你截断。例如:

backItem.title = "Birthdays/Anniversaries" // Get's converted to "Back".
backItem.title = "Birthdays/Anniversa…" // Fits and shows as is.