如何获取 iOS 中的导航栏高度?


导航栏出现在应用屏幕顶部。要了解有关它的更多信息

https://developer.apple.com/design

https://developer.apple.com/documentation

获取导航栏的高度变得很重要,如果你有多个具有不同 UI 和需求的视图控制器。如果你不知道如何获取导航栏的高度或根据需要进行修改,这会变得很麻烦。让我们来看看如何获取导航栏的高度。

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)
   }
}

更新于: 30-Jul-2019

3 千次浏览量

开启你的职业生涯

完成课程认证

开始
广告
© . All rights reserved.