UITabBarController 是用来管理导航栏的
导航栏是通过数组来管理数据的,用属性viewCintrollers来保存,tabbar也是 导航栏(44) + 状态栏(20) = 64 = 8 * 8 tabber = 49 = 7*7
创建完导航栏之后,创建一个tabbar的按钮内容 naVc.tabBarItem
RootViewController *rootVc = [[RootViewController alloc] init];
UINavigationController *naVc = [[UINavigationController alloc] initWithRootViewController:rootVc];
// UINavigationController 通过数组保存viewControllers属性保存
// 包括:状态栏(高度20) + 导航栏(高度44)
// Tabbarcontroller管理navigation
// 创建一个tabbar的按钮内容
// tabbar的高度是49
naVc.tabBarItem = [[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemSearch tag:1000] autorelease];
创建按钮有三种方法 1.initWithTabBarSystemItem:UITabBarSystemItemSearch tag:1000
2.initWithTitle:@"ok" image:[UIImage imageNamed:@"1.png"] tag:1001
3.initWithTitle:@"man" image:[UIImage imageNamed:@"back.png"] selectedImage:[UIImage imageNamed:@"add.png"]
用来显示显示的个数的属性:tabBarItem.badgeValue
// 显示消息的个数
naVc.tabBarItem.badgeValue = @"+99";
创建tabbarController
UITabBarController *tabVc = [[UITabBarController alloc] init];
设置tabVc管理的naVc,通过viewControllers属性管理
tabVc.viewControllers = @[naVc, secNAVC, thNavc, forNaVc, fifNavc, sixNaVc];
设置window的根视图
self.window.rootViewController = tabVc;
设置tabbar的外观(默认是半透明)
tabVc.tabBar.translucent = NO;
更换点击图标的颜色
tabVc.tabBar.tintColor = [UIColor purpleColor];
tabbar的协议方法(tabbar的点击方法)dids....
#pragma mark 这个方法相当于tab的点击方法
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
NSLog(@"miao");
// 通过传过来的viewcontroller来找到badgeValue
viewController.tabBarItem.badgeValue = nil;
}