【问题标题】:How do I remove the navigation bar title?如何删除导航栏标题?
【发布时间】:2018-01-09 21:30:05
【问题描述】:

也许这是我缺乏谷歌技能,但我似乎无法找到合适的代码来删除我的导航栏上的标题。也在这里搜索过,但我能找到的只是删除后退按钮文本或更改标题颜色...有什么想法吗?

【问题讨论】:

标签: swift uiviewcontroller navigationbar


【解决方案1】:

您可能已经在 Storyboard 中设置了标题。在 Storyboard 中将其删除或在您的 UIViewController 实例的 viewDidLoad() 中将标题设置为 nil

override func viewDidLoad() {
    super.viewDidLoad()
    self.title = nil
}

【讨论】:

    【解决方案2】:

    以编程方式在您的UIViewController() 实例的viewDidLoad() 中设置导航栏标题空字符串:

    override func viewDidLoad() {
        super.viewDidLoad()
    
        self.navigationItem.title = ""
    }
    

    【讨论】:

      【解决方案3】:

      删除代码中标题的机制总是像.remove()
      在 Swift5 中,我们有 titleView?.removeFromSuperview() 删除标题视图和 title?.removeAll() 删除标题中的文本:

      //M: find your controller -> tabBarController -> navigationItem -> titleView/title -> remove
      self.tabBarController?.navigationItem.titleView?.removeFromSuperview()
      self.tabBarController?.navigationItem.title?.removeAll()
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-12-20
        • 2015-07-06
        • 1970-01-01
        • 2014-11-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多