RTRootNavigationController是iOS開(kāi)發(fā)里面經(jīng)常用到的第三方框架,可以用cocoapods導(dǎo)入項(xiàng)目中布朦,使用TRootNavigationController可以自定義導(dǎo)航欄
參考:http://www.cocoachina.com/ios/20161121/18137.html
-
TRootNavigationController的使用
TRootNavigationController可以達(dá)到這個(gè)效果:頁(yè)面手勢(shì)返回時(shí) 導(dǎo)航條跟隨控制器一起滑動(dòng)
1.在AppDelegate里面設(shè)置根視圖
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類導(dǎo)入一下TRootNavigationController.h頭文件就行,也可以把TRootNavigationController.h放到pch文件里面请敦,base類贸营,每個(gè)vc都需要繼承它
base.h
#import <UIKit/UIKit.h>
//導(dǎo)入一下
#import <RTRootNavigationController/RTRootNavigationController.h>
@interface CFFBaseViewController : UIViewController
@end
base.m
//重寫RTRootNavigationController里方法贾漏,修改返回按鈕;在其他控制器想設(shè)置導(dǎo)航欄不一樣具伍,可以在其他控制器重寫該方法修改當(dāng)前控制器的導(dǎo)航欄
- (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導(dǎo)航欄的類
UIViewController *vc1 = [CFFMainViewController new];
RTContainerNavigationController *nc1 = [[RTContainerNavigationController alloc] initWithRootViewController:vc1];
vc1.tabBarItem.title = @"首頁(yè)";
UIViewController *vc2 = [CFFDynamicViewController new];
RTContainerNavigationController *nc2 = [[RTContainerNavigationController alloc] initWithRootViewController:vc2];
vc2.tabBarItem.title = @"動(dòng)態(tài)";
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.視圖跳轉(zhuǎn)
CFFPlayViewController *playVC = [[CFFPlayViewController alloc] init];
//導(dǎo)入RTRootNavigationController,依然可以用自帶的導(dǎo)航欄跳轉(zhuǎn)
[self.navigationController pushViewController:playVC animated:YES];
//使用RTRootNavgationController的跳轉(zhuǎn)方式
// [self.rt_navigationController pushViewController:playVC animated:YES complete:nil];
- 導(dǎo)航欄屬性修改
//修改導(dǎo)航欄顏色 可以設(shè)置barTintColor
tintColor:item字體顏色(修改所有界面的導(dǎo)航欄按鈕沿猜,如果使用了RTRootNavigatonController枚荣,則設(shè)置該屬性,只改變當(dāng)前導(dǎo)航欄按鈕) barTintColor:導(dǎo)航欄背景顏色(修改所有界面的導(dǎo)航欄啼肩,如果使用了RTRootNavigatonController橄妆,則設(shè)置該屬性衙伶,只改變當(dāng)前導(dǎo)航欄)
self.navigationController.navigationBar.barTintColor = [UIColor groupTableViewBackgroundColor];
修改導(dǎo)航欄顏色 也可以導(dǎo)航欄背景圖片
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:[UIColor grayColor]] forBarMetrics:UIBarMetricsDefault]; //導(dǎo)航欄背景圖片
//隱藏導(dǎo)航欄分割線
[self.navigationController.navigationBar setClipsToBounds:YES];
//修改導(dǎo)航欄分割線 設(shè)置陰影分割線,和背景圖片一起設(shè)置才有效果
如果想隱藏分割線害碾,也可以陰影分割線矢劲,和背景圖片設(shè)置一樣的顏色
[self.navigationController.navigationBar setShadowImage:[UIImage imageWithColor:[UIColor redColor]]]; //導(dǎo)航欄分割線
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:[UIColor grayColor]] forBarMetrics:UIBarMetricsDefault]; //導(dǎo)航欄背景圖片