Custom navbar

My notes on customising UINavigationBar

Thoughts on Using native navigation class

  • Works for simple cases
  • You can’t see the code your subclassing

Thoughts on using custom nav class:

  • Supports responsive table view setups
  • Supports custom look and feel
  • Supports custom translucent background that blends into the background color


  • UIBarButtonItem is used for ´back-button´
  • to go back use. navigationController?.popViewController(animated: true)


  • Apple docs:
  • Customize native navbar anim:
  • Add alert-view bellow nav-bar:
  • Customize color in transition: and


From here:

// Hide navbar
override func viewWillAppear(_ animated: Bool) {
    self.navigationController?.isNavigationBarHidden = true
// subclassing:
let navBar: UINavigationBar = {
    let view = UINavigationBar()
    view.backgroundColor = .clear
    view.isTranslucent = true
    view.translatesAutoresizingMaskIntoConstraints = false
    return view
// You can set custom Back button as like below
self.navigationItem.hidesBackButton = true
let backButton = UIBarButtonItem(image: UIImage(named: "image_name"), style: .plain, target: self, action: #selector(Class.methodName))
backButton.tintColor = UIColor.white
self.navigationItem.leftBarButtonItem = backButton

Custom API:

// leftBtn
// title
// rightBtn