2016-11-05 70 views
-2

想要爲導航標題購物清單添加頂部的額外空間。我該怎麼做?不要在故事板中的導航項目的屬性中看到選項。它接近日期,應用程序頂部的電池圖標。從導航標題頂部添加空間

附加截圖。

enter image description here

嘗試下面的代碼,它使用swift2

override func viewDidLoad() { 
     super.viewDidLoad() 
     // Do any additional setup after loading the view, typically from a nib. 
       navigationController?.navigationBar.setTitleVerticalPositionAdjustment(15,forBarMetrics: UIBarMetrics.Default) // set any number you want between -20 to 15 


    } 
+0

所以要進一步移動標題垂直定位下來。可您發佈的模擬器截圖你問題 – Joe

+0

是垂直定位進一步向下。直接在iphone上運行,不能在模擬器上截取屏幕截圖。 – Arav

+0

讓我知道。代碼適合你嗎? – Joe

回答

0

試試這個代碼不工作:測試在斯威夫特3.

注:方法只有1部作品,如果你的VC嵌入navigationController。在你的情況下,你只使用導航欄顯示標題。所以,使用方法2.

方法1:

navigationController?.navigationBar.setTitleVerticalPositionAdjustment(5, for: UIBarMetrics.default) // set any number you want between -20 to 15 

方法2:

navigationBar.setTitleVerticalPositionAdjustment(10, for: UIBarMetrics.default) // navigationBar is the name of your navBar.. 

輸出:

enter image description here

+0

使用swift2嘗試從-20到15的標題位置不移動的不同值。在viewdidload方法中複製代碼。粘貼編輯部分的代碼 – Arav

+0

抱歉,延遲將嘗試並讓你知道 – Arav