2017-06-02 122 views
0

我設法增加了我的導航欄的高度,但是我遇到了問題,那個標題和按鈕位於導航欄的底部。垂直中心導航欄視圖

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

enter image description here

我試圖設置偏移,使用

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) 

其實,設置只適用於我的頭銜,以及按鈕欄的位置保持不變。

但我不認爲我的解決方案是最好的。

+0

你爲什麼不展示你究竟是如何增加導航欄高度的? –

+0

有關此問題的評論中的夫婦鏈接可能會有所幫助:https://stackoverflow.com/questions/44181264/move-navigationbars-left-and-right-barbuttonitems-vertically-upwards – DonMag

回答

0

增加導航欄的大小不是一個好習慣。相反,您可以在導航欄下以相同顏色添加uiview右側,並刪除導航欄邊框,使其看起來像增加了高度。下面是一個例子,說明yelp是如何做到的。 enter image description here