2017-06-26 34 views
0

任何人都可以建議如何有效實現以下圖片中顯示的內容嗎?iOS - 帶多行標題的自定義導航欄

Expected outcome with title

總結:

  1. titleView對準接近Back按鈕。我嘗試設置titleView的框架,但它只在固定範圍內變化
  2. title是多行左對齊的。我想這可以只通過設置,想必.textAlignmentnumberOfLines特性可以實現,title label
  3. title.top似乎與backButton.top
  4. 對齊標題下的灰線不會是topLayoutGuide,因爲它似乎可定製至少在其長度
  5. 導航欄本身是超過64p - 默認的高度,並可以計算?

到目前爲止,我已經嘗試添加UIViewUILabel子視圖導航條和它的排序工作,但看起來像

What is achieved so far

+0

可能是[此](https://stackoverflow.com/questions/34298383/multiline-navigationbar-title) – Dopapp

+0

號的副本問題不在於「多行」部分,而在於標題與後退按鈕的對齊方式以及導航欄本身的高度 – unspokenblabber

+0

[this]怎麼樣?(https://stackoverflow.com/questions/29949969/添加一個標題到左側的導航欄) – Dopapp

回答

0

你可以試試下面的代碼。

目標C

UILabel *lblTitle = [[UILabel alloc] init]; 
lblTitle.textColor = [UIColor blackColor]; 
[email protected]"This is a multiline string for the navBar details"; 
lblTitle.font=[UIFont systemFontOfSize:16]; 
lblTitle.frame = CGRectMake(0, 0, 150, 50); 
lblTitle.numberOfLines=3; 
self.navigationItem.titleView = lblTitle; 

迅速

let label = UILabel(frame: CGRect(x:0, y:0, width:150, height:50)) 
    label.backgroundColor = UIColor.clear 
    label.numberOfLines = 3 
    label.font = UIFont.boldSystemFont(ofSize: 16.0) 
    label.textColor = UIColor.blackColor 
    label.text = "This is a multiline string for the navBar details" 
    self.navigationItem.titleView = label 
+0

這是@Dopapp指出,正如我所提到的,我已經試過這個。這隻將標籤限制在navigationItem的titleView的固定範圍內。 – unspokenblabber