iOS中設定導覽列標題的字型顏色和大小

來源:互聯網
上載者:User

標籤:

 

iOS中設定導覽列標題的字型顏色和大小,有需要的朋友可以參考下。




在平時開發項目的時候,難免會遇到修改導覽列字型大小和顏色的需求,一般使用自訂視圖的方法,其實還存在一種方法。

 

方法一:(自訂視圖的方法,一般人也會採用這樣的方式)

 

就是在導航向上添加一個titleView,可以使用一個label,再設定label的背景顏色透明,字型什麼的設定就很簡單了。

 

 

 

//自訂標題視圖

 

UILabel *titleLabel = [[UILabel 
alloc] initWithFrame:CGRectMake(0, 
0, 200, 44)];

 

titleLabel.backgroundColor = [UIColor 
grayColor];

 

titleLabel.font = [UIFont 
boldSystemFontOfSize:20];

 

titleLabel.textColor = [UIColor 
greenColor];

 

titleLabel.textAlignment = 
NSTextAlignmentCenter;

 

titleLabel.text = 
@"新聞";

 

self.navigationItem.titleView = titleLabel;

 



 

方法二:(在預設顯示的標題中直接修改檔案的大小和顏色也是可以的)

 

 

 

[self.navigationController.navigationBar setTitleTextAttributes:

 

@{NSFontAttributeName:[UIFont systemFontOfSize:19],

 

NSForegroundColorAttributeName:[UIColor redColor]}];

 

方式二相對於方式一而言更加簡單方便

iOS中設定導覽列標題的字型顏色和大小

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.