How to get the Navigation Bar height in iOS?


A navigation bar appears at the top of an app screen. To read more about it

https://developer.apple.com/design

https://developer.apple.com/documentation

Getting height of Navigation bar becomes important if you’ve multiple view controllers having different UI and requirement. It becomes hectic if you’re not aware how to get the height of the same or modify as per need. Let’s see how we can get the height of Navigation bar.

import UIKit
class ViewController: UIViewController {
   override func viewDidLoad() {
      super.viewDidLoad()
      let navBarHeight = UIApplication.shared.statusBarFrame.size.height +
         (navigationController?.navigationBar.frame.height ?? 0.0)
      print(navBarHeight)
   }
}

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 30-Jul-2019

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements