What is the top bar height of iPhone X?
Asked Answered
L

8

61

I would like to know exact height of top bar of iPhone X. Could you please mention the status bar and navigation bar height of iPhone X. Please help me.

enter image description here

Laveralavergne answered 13/9, 2017 at 12:30 Comment(0)
B
94

The display on iPhone X, however, is 145pt taller than a 4.7" display, resulting in roughly 20% additional vertical space for content.

for more information you get HIG for iphone X from apple documents and detail description in here1 and here2

enter image description here

status bar height

previously 20pt, now 44pt

Because of the sensors on top of the display, the new status bar is split in 2 parts. If your UI is doing something special with that space (previously 20pt high, now 44pt), because it will be taller on the iPhone X. Make sure that it can be dynamically changed in height. A great thing is that the height won’t be changed if a user makes a phone call or is using a navigation app, which was previously the case on other iPhones.

enter image description here

portrait

Navigation bar height as normal 88 and large title time 140

  • Standard title - 44pt (88pt with Status Bar)
  • Large title - 140pt
  • bottom bar - 34pt

Landscape

  • Standard title - 32pt
  • bottom bar - 21pt
Broom answered 13/9, 2017 at 12:32 Comment(1)
Typo: Navigation bar height as normal is 44pt. If you include the status bar then yes it's 88pt.Atticism
A
28

Nav bar is 44pt as usual (when no large titles) and the status bar has increased from 20pt to 44pt. Here's what you can type in the debugger to verify it:

enter image description here

Atticism answered 15/11, 2017 at 21:13 Comment(1)
Why screenshot? -.-Parvenu
U
16

You can programmatically obtain the navigation bar's height by using safeAreaInsets on the view in the contained view controller:

let navBarHeight = view.safeAreaInsets.top

This will account for whether it's a large title navigation bar or not, and whether or not there's a search bar attached to it.

See the safeAreaInsets documentation for more information.

Uninterrupted answered 9/11, 2017 at 21:50 Comment(0)
C
12

You can use the navigation bar's .frame property to figure out the overall height of the top bar area:

Swift 5.0:

let xBarHeight = (self.navigationController?.navigationBar.frame.size.height ?? 0.0) + (self.navigationController?.navigationBar.frame.origin.y ?? 0.0)

ObjC:

CGRect navbarFrame = self.navigationController.navigationBar.frame;
float topWidth  = navbarFrame.size.width;
float topHeight = navbarFrame.size.height + navbarFrame.origin.y;

I suppose this is a bit of a cheat, but adding the navbar's height with its y origin seems to give the correct total height regardless of device.

Clarkia answered 1/11, 2017 at 20:1 Comment(1)
Nice solution. ThanksTarratarradiddle
T
12

You can simply get it in the next way (Swift 3):

let barHeight = navigationController?.navigationBar.frame.maxY

To get correct value make sure that you call it after setting prefersLargeTitles

navigationController?.navigationBar.prefersLargeTitles = false
Thorr answered 22/11, 2017 at 8:30 Comment(0)
G
4

There is no specification in Apple Docs

Apple Docs

According to Geoff Hackworth its 88

Navigation title types :

  • Standard title
  • Large title

Increasing navigation bar in iOS 11

navigationController?.navigationBar.prefersLargeTitles = true
Generalist answered 13/9, 2017 at 13:11 Comment(0)
B
3

If you're using a UIWindow and you need to know the top bar height you can use this:

// old way of getting keyWindow
//guard let keyWindow = UIApplication.shared.keyWindow else { return }

// new way of getting keyWindow
guard let keyWindow = UIApplication.shared.windows.first(where: { $0.isKeyWindow }) else { return }

let navBarHeight = keyWindow.safeAreaInsets.top

print("navBarHeight:" , navBarHeight)

I got the idea from @Paolo's answer

Borglum answered 7/5, 2020 at 1:1 Comment(0)
C
0

Use it if you want to know where need start content

extension UIViewController {
  var navigationBarbarContentStart: CGFloat {
    return self.navigationBarTopOffset + self.navigationBarHeight
  }
  var navigationBarTopOffset: CGFloat {
    return self.navigationController?.navigationBar.frame.origin.y ?? 0
  }

  var navigationBarHeight: CGFloat {
    return self.navigationController?.navigationBar.frame.height ?? 0
  }
}
Consuetudinary answered 4/10, 2019 at 11:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.