2

I can't seem to find the proper code to remove the title(s) on my navigation bar. Any ideas?

maxmitz
  • 258
  • 1
  • 4
  • 17
Joakim Sjöstedt
  • 824
  • 2
  • 9
  • 18

3 Answers3

3

You have probably set the title in Storyboard. Remove it in Storyboard or set the title to nil in viewDidLoad() of your UIViewController instance:

override func viewDidLoad() {
    super.viewDidLoad()
    self.title = nil
}
shallowThought
  • 19,212
  • 9
  • 65
  • 112
3

Programmatically set navigation bar title empty string in viewDidLoad() of your UIViewController() instance:

override func viewDidLoad() {
    super.viewDidLoad()

    self.navigationItem.title = ""
}
Emre Ozdil
  • 401
  • 6
  • 12
2

The mechanism to remove the title in code is always like .remove().
In Swift5, we have titleView?.removeFromSuperview() to remove the title view and title?.removeAll() to remove the text in title:

//M: find your controller -> tabBarController -> navigationItem -> titleView/title -> remove
self.tabBarController?.navigationItem.titleView?.removeFromSuperview()
self.tabBarController?.navigationItem.title?.removeAll()
סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
Michael Lin Liu
  • 131
  • 2
  • 2