What is the top bar height of iPhone X?

后端 未结 8 1555
醉梦人生
醉梦人生 2020-12-02 08:40

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.

相关标签:
8条回答
  • 2020-12-02 09:26

    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.

    0 讨论(0)
  • 2020-12-02 09:26

    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
      }
    }
    
    0 讨论(0)
提交回复
热议问题