我试图将 navigationBar 的所有元素都放在垂直中心,但我不知道该怎么做?
黄色上面的灰色部分是navigationBar。正如我们所看到的,导航栏的标题和其他元素没有垂直居中。
我该怎么做?
到目前为止我的代码:
let navigationItem = UINavigationItem()
navigationItem.title = sTitle;
navigationBar.frame = CGRectMake(0,0,screenwidth, 50);
navigationBar.titleTextAttributes = [ NSFontAttributeName: titleFont, NSForegroundColorAttributeName: UIColor.blackColor()]
self.view.addSubview(navigationBar);
最佳答案
如果隐藏状态栏,您可以将所有元素居中,这可以通过将以下内容添加到您的 Info.plist 中来实现:
<key>UIStatusBarHidden</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
你的 ViewController 看起来像这样:
您可以在这个链接中看到更多隐藏状态栏的方法:hide Status bar
关于ios - 导航栏项目未垂直居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36258996/