iOS設定UINavigationBar 的樣式

來源:互聯網
上載者:User

標籤:

為了方便示範,我用storyBoard建立了一個基本的導覽列 並在代碼中獲得了NavgationBar

 

UINavigationBar *bar = self.navigationController.navigationBar;

 

1  

 

 

[bar setTintColor:[UIColor whiteColor]];

 

設定導覽列Title顏色

 

123 [
bar setTitleTextAttributes:@{                                  NSForegroundColorAttributeName :[UIColor whiteColor]                                  }];

 

如果需要設定返回按鈕的顏色,設定bar的tintColor即可

 


 

 

 

設定UINavigationBar背景圖片

 

?
1 [bar setBackgroundImage:[UIImage imageNamed:@"bg.png"] forBarMetrics:UIBarMetricsDefault];
?
1  


 

 

 

 

設定UINavigationBar全透明, 此處隨便設定一張圖片即可,重要的是BarMetrics屬性決定了bar的樣式

 

?
1 [bar setBackgroundImage:[UIImage imageNamed:@"bg.png"] forBarMetrics:UIBarMetricsCompact];
?
1  


 

 

 

 

設定導覽列下方不顯示內容,此時導覽列無透明度

 

?
1 self.extendedLayoutIncludesOpaqueBars = YES;
?
1  
使用storyBoard需要在控制器中設定

 

 



完成之後就是這樣了,但是bar的tintColor會成為下方內容的顏色。 

 

 

同時在滾動視圖中 設定

automaticallyAdjustsScrollViewInsets屬性可以控制滾動內容是否會在bar下方顯示。

 

 

 

iOS設定UINavigationBar 的樣式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.