【iOS開發-UITabBarController】UITabBarController上面的UINavigationController的設定,uitabbarcontroller

來源:互聯網
上載者:User

【iOS開發-UITabBarController】UITabBarController上面的UINavigationController的設定,uitabbarcontroller
自訂導覽列

為了保證項目的導覽列效果一直,一般都會設定導覽列的樣式一樣

①自訂一個NavigationController類,繼承與UINavigationController類
②更改所有的UITabBarController下面的UINavigationController的class屬性為自訂類形式
③主要是取得導覽列的appearance對象,操作它就設定導覽列的主題

UINavigationBar *navBar = [UINavigationBar appearance];

④導覽列背景

//設定導覽列背景的- (void)setBackgroundImage:(UIImage *)backgroundImage forBarMetrics:(UIBarMetrics)barMetrics;

⑤設定標題

@property(nonatomic,copy) NSDictionary *titleTextAttributes;// 字典中能用到的key在UIStringDrawing.h中// 最新版本的key在UIKit架構的NSAttributedString.h中

自訂導覽列按鈕

UIBarButtonItem *item = [UIBarButtonItem appearance];

iOS6導覽列背景的出圖規格
非retina:320x44 px
retina:640x88 px

iOS7導覽列背景的出圖規格
retina:640x128 px

自訂NavigationController

自訂導航控制器的步驟:建立一個類,繼承自UINavigationController

自訂導航控制器的價值
重寫push方法就可以攔截所有壓入棧中的子控制器,統一做一些處理

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated;

重寫pop方法就可以攔截所有子控制器的出棧

- (UIViewController *)popViewControllerAnimated:(BOOL)animated;

為了在push控制器時隱藏UITabBar,需要做以下設定

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{    viewController.hidesBottomBarWhenPushed = YES;    [super pushViewController:viewController animated:animated];}

initailize、load方法的區別
initailize、load都是類方法
當一個類被裝載進記憶體時,就會調用一次load方法(當時這個類還不可用)
當第一次使用這個類時,就會調用一次initailize方法

聯繫我們

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