Search code examples
iosiphoneswiftuinavigationcontrolleruinavigationbar

Setting UINavigationController Bar title in Swift 2.0


I am trying to set my navigation bar title but no matter where I set the title it will not show. I have the background color set and that change is applied, just not the title. Please advise.

  import UIKit

  class CustomNavigationController: UINavigationController{
      override func viewDidLoad() {
          super.viewDidLoad()
          navigationBar.tintColor = UIColor.themeDarkGray()
          navigationBar.barTintColor = UIColor.themeDarkGray()
          navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor()]  // Title's text color
          self.title = "Title Here"

      }
  }

Solution

  • Try this:

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

    It should work! :)