RTRootNavigationController的使用

RTRootNavigationController是iOS開發里面經常用到的第三方框架,可以用cocoapods導入項目中,使用TRootNavigationController可以自定義導航欄

參考:http://www.cocoachina.com/ios/20161121/18137.html

  • TRootNavigationController的使用
    TRootNavigationController可以達到這個效果:頁面手勢返回時 導航條跟隨控制器一起滑動


    B8CA0FAFD597D39B281725D10D42F92E.jpg

1.在AppDelegate里面設置根視圖

AppDelegate.m
 self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self.window setBackgroundColor:[UIColor whiteColor]];
self.window.rootViewController = [[RTRootNavigationController alloc] initWithRootViewController:[[CFFRootViewController alloc] init]];
    [self.window makeKeyAndVisible];

2.在base類導入一下TRootNavigationController.h頭文件就行,也可以把TRootNavigationController.h放到pch文件里面,base類,每個vc都需要繼承它
base.h

#import <UIKit/UIKit.h>
//導入一下
#import <RTRootNavigationController/RTRootNavigationController.h>
@interface CFFBaseViewController : UIViewController
@end

base.m
//重寫RTRootNavigationController里方法,修改返回按鈕;在其他控制器想設置導航欄不一樣,可以在其他控制器重寫該方法修改當前控制器的導航欄

- (UIBarButtonItem *)rt_customBackItemWithTarget:(id)target action:(SEL)action {
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:[UIImage imageNamed:@"left"] forState:UIControlStateNormal];
    [btn sizeToFit];
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    return [[UIBarButtonItem alloc] initWithCustomView:btn];
}

3.如果有底部欄,在root根視圖里面

 //RTContainerNavigationController是RTRootNavigationController導航欄的類
    UIViewController *vc1 = [CFFMainViewController new];
    RTContainerNavigationController *nc1 = [[RTContainerNavigationController alloc] initWithRootViewController:vc1];
    vc1.tabBarItem.title = @"首頁";
    
    UIViewController *vc2 = [CFFDynamicViewController new];
    RTContainerNavigationController *nc2 = [[RTContainerNavigationController alloc] initWithRootViewController:vc2];
    vc2.tabBarItem.title = @"動態";
    
    UIViewController *vc3 = [CFFMeViewController new];
    RTContainerNavigationController *nc3 = [[RTContainerNavigationController alloc] initWithRootViewController:vc3];
    nc2.rdv_tabBarItem.title = @"我的";
    
    UIViewController *centerVC = [[ViewController alloc] init];
    RTContainerNavigationController *ncCenter = [[RTContainerNavigationController alloc] initWithRootViewController:centerVC];   
    self.viewControllers = @[nc1,nc2,ncCenter,nc3];

4.視圖跳轉

CFFPlayViewController *playVC = [[CFFPlayViewController alloc] init];
        //導入RTRootNavigationController,依然可以用自帶的導航欄跳轉
        [self.navigationController pushViewController:playVC animated:YES];
        //使用RTRootNavgationController的跳轉方式
//        [self.rt_navigationController pushViewController:playVC animated:YES complete:nil];
  • 導航欄屬性修改
    //修改導航欄顏色 可以設置barTintColor
    tintColor:item字體顏色(修改所有界面的導航欄按鈕,如果使用了RTRootNavigatonController,則設置該屬性,只改變當前導航欄按鈕) barTintColor:導航欄背景顏色(修改所有界面的導航欄,如果使用了RTRootNavigatonController,則設置該屬性,只改變當前導航欄)
    self.navigationController.navigationBar.barTintColor = [UIColor groupTableViewBackgroundColor];

修改導航欄顏色 也可以導航欄背景圖片

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:[UIColor grayColor]] forBarMetrics:UIBarMetricsDefault];  //導航欄背景圖片

//隱藏導航欄分割線
[self.navigationController.navigationBar setClipsToBounds:YES];

//修改導航欄分割線 設置陰影分割線,和背景圖片一起設置才有效果
如果想隱藏分割線,也可以陰影分割線,和背景圖片設置一樣的顏色

    [self.navigationController.navigationBar setShadowImage:[UIImage imageWithColor:[UIColor redColor]]];  //導航欄分割線
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:[UIColor grayColor]] forBarMetrics:UIBarMetricsDefault];  //導航欄背景圖片
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • 發現 關注 消息 iOS 第三方庫、插件、知名博客總結 作者大灰狼的小綿羊哥哥關注 2017.06.26 09:4...
    肇東周閱讀 12,200評論 4 61
  • 聽說沒了心的人不會痛 你就得了失心瘋 滿口說著沒了心的人不會痛 起風了 風冰冷地穿透了那塊空缺的位置 沒了心的人不...
    鍍月閱讀 502評論 0 4
  • 佛說,看得見的 看不見的 皆在咫尺之間 我說,看的見的是真實 看不見的是虛無 佛又說,真實和虛無之間 也只有一步之...
    莫暇閱讀 637評論 3 10
  • 一天晚上,玩成語接龍。 寶寶用了兩個詞形容媽媽:和顏悅色、暴跳如雷。說媽媽當時是和顏悅色,發怒時就是暴跳如雷。 此...
    小學生家長充電寶閱讀 331評論 0 1