UINavigationController,uinavigationbar

來源:互聯網
上載者:User

UINavigationController,uinavigationbar

知識點:

1)UINavigationController

2)UINavigationBar

3)UINavigationItem

4)UIToolBar

======================================================

一、UINavigationController

 

1、UINavigationController介紹

1)UINavigationController是導航控制器,它通過棧的方式控制當前顯示在螢幕上的是哪個控制器。

2)它可以通過壓入(push)和彈出(pop)來改變控制器的層次。

3)自動提供返回(Back)按鈕,以回到上一個壓入的控制器,不需要額外編程

4)UINavigationController會提供控制器切換的動畫效果

5)   UINavgationController通過棧的形式管理多個UIViewController(即多個介面)

6)可以管理當前在導航條(navigationBar)上的導覽按鈕

7)UINavgationController為每個接受它管理的UIViewController自動添加UINavigationBar

8)包括四部分: ️.UINavigationController 

  ️.UIViewController

    ️.UINavigationBar

    ️.UINavigationItem

2、導航控制器的跳轉

1)pushViewController: animated:  跳轉,切換到下一個視圖控制器(壓棧)

2)popViewControllerAnimated:  返回上一層(出棧)

3)popToRootViewControllerAnimated:  返回root視圖控制器(根視圖控制器)

4)popToViewController:  animated:  返回到指定層

5)   setViewControllers:(NSArray<UIViewController *>)animated:同時為UINavgationController設定所有的UIViewController

=====================================================

 

二、UINavigationBar(受UINavigationController管理)

1、UINavigationBar位於螢幕頂端的控制項,通常只是作為多個UINavigationBar的容器,同樣是以棧的 形式來管理多個UINavigationItem控制項

2、UINavigationBar常用方法和屬性

1)backgroundColor  設定導覽列的背景色,毛玻璃邊效果

2)barTintColor  設定純色背景 3)barStyle  狀態列系統樣式(很少使用,一般我們都會加上背景圖片)

4)setBackgroundImage: forBarMetrics: 

7.0之前,導航的高度為44

    7.0之後,導航的高度為64

  Metrics 指在什麼狀態下的圖片(橫32,豎64)

a)UIBarMetricsDefault 豎屏

(以下兩個方法使用之前可以先判斷當前的版本號碼再決定使用哪個)

通過該方法擷取版本號碼:[[[UIDevice currentDevice] systemVersion] floatValue]

b)UIBarMetricsCompact 橫屏 iOS8.0之後的方法

c)UIBarMetricsLandscapePhone iOS8.0之前的橫屏方法

5)   hidden屬性,YES為隱藏導覽列,NO為顯示

=========================================================

 

三、UINavigationItem

 

1、UINavigationItem常用方法和屬性

 

標題相關

1)title 設定導航標題

2)titleTextAttributes  設定導覽列標題的文字大小(key:NSFontAttributeName)和顏色(key:NSForegroundColorAttributeName)

3)titleView  設定標題的UIView(可以使用自訂的)

按鈕相關(UIBarButtonItem)主要有右按鈕rightBarButtonItem、左按鈕leftBarButtonItem,還有多個按鈕

rightBarButtonItems:(NSArray)、leftBarButtonItems:(NSArray)

4)initWithBarButtonSystemItem: target action:  系統內建的樣式

5)initWithCustomView:  自訂item樣式

6)initWithImage: style: target: action: 以圖片方式設定item樣式

7)initWithTitle: style: target: action: 以文字樣式設定item

8)tintColor 渲染item顏色

9)彈簧效果

  這是系統的樣式,得指定彈開的寬度:UIBarButtonSystemItemFixedSpace 

  width  設定彈開的寬度

     這是系統的樣式,會自動彈開:UIBarButtonSystemItemFlexibleSpace 

10)hidesBackButton 該屬性設定是否顯示左上方的back按鈕,YES為隱藏

======================================================

 

四、UIToolBar

 

1、UIToolBar介紹

1)UIToolBar存在於UINavigationController控制器中

     2)UIToolBar預設顯示在UINavigationController的底部位置,且預設被隱藏

     3)當我們需要在螢幕的底部加一些按鈕時我們就可以使用UIToolBar來設定他,不需要自己去建立UIView

     4)建立UIToolBar需要先建立一個UINavigationController控制器

 

2、UIToolBar的常用方法和屬性

    1)setBackgroundImage: forToolbarPosition: barmetrics:  

設定toolBar的背景圖片,UIToolBar的高度為44

    2)setToolBarHidden:  animated:  設定toolBar的隱藏和顯示

 

 

 

 

 

 

 

 

聯繫我們

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