[英]center navigation bar views vertically
I managed to increase the height of my navigation bar, but I faced with the problem, that title and buttons are situated in the bottom of navigator bar. 我设法增加了导航栏的高度,但是我遇到了这个问题,标题和按钮位于导航栏的底部。
extension UINavigationBar {
open override func sizeThatFits(_ size: CGSize) -> CGSize {
let v = self.value(forKey: "frame") as? CGRect
return v?.size ?? CGSize(width: UIScreen.main.bounds.width, height: 44)
}
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationBar.frame = CGRect(x: 0, y: 0, width: bounds.width, height: 64)
}
I tried to set offset, using 我尝试使用
navigationBar.setTitleVerticalPositionAdjustment(-10, for: .default)
navigationItem.leftBarButtonItem?.setBackgroundVerticalPositionAdjustment(-10, for: .default)
navigationItem.rightBarButtonItem?.setBackgroundVerticalPositionAdjustment(-10, for: .default)
navigationItem.rightBarButtonItem?.setBackButtonBackgroundVerticalPositionAdjustment(-10, for: .default)
navigationItem.leftBarButtonItem?.setBackButtonBackgroundVerticalPositionAdjustment(-10, for: .default)
Actually that setting only apply to my title, and the position of button bars remain the same. 实际上,该设置仅适用于我的标题,并且按钮栏的位置保持不变。
But I don't think my solution is the best. 但是我认为我的解决方案不是最好的。
Its not a good practice to increase the size of the navigation bar. 增大导航栏的大小不是一个好习惯。 Instead you can add a uiview right under navigation bar with same color and remove the navigation bar border to make to look like height increased.
取而代之的是,您可以在导航栏下方添加具有相同颜色的uiview,然后删除导航栏边框以使其看起来像高度增加了。 Here is an example how yelp does it.
这是yelp如何做到的示例。
I posted the solution of this problem in another thread. 我在另一个线程中发布了该问题的解决方案。 Hope this helps.
希望这可以帮助。
vertically aligning UINavigationItems 垂直对齐的UINavigationItems
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.