TabBarController
创建控制器 创建导航控制器
FirstViewController *firstVC = [[FirstViewController alloc] init];
UINavigationController *firstNaVC = [[UINavigationController alloc] initWithRootViewController:firstVC];
firstVC.view.backgroundColor = [UIColor redColor];
SecondViewController *secondVC = [[SecondViewController alloc] init];
secondVC.view.backgroundColor = [UIColor greenColor];
UINavigationController *secondNaVC = [[UINavigationController alloc] initWithRootViewController:secondVC];
添加标题
firstVC.tabBarItem.title = @"首页"
添加图片
firstVC.tabBarItem.image = [UIImage imageNamed:@"01-refresh"]
非镂空图显示
secondVC.tabBarItem.image = [[UIImage imageNamed:@"11"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
设置选中的图片
firstVC.tabBarItem.selectedImage = [UIImage imageNamed:@"02-redo"];
设置tabBarItem上的 红色提示按钮
secondVC.tabBarItem.badgeValue = @"22"
把视图添加进tabBarController
self.viewControllers = @[firstNaVC, secondNaVC];
设置bar的颜色
self.tabBar.barTintColor = [UIColor yellowColor];
设置bar的填充色
self.tabBar.tintColor = [UIColor orangeColor];
设置bar的背景图片
self.tabBar.backgroundImage = [UIImage imageNamed:@"tabBar"];
设置默认选中的页面
self.selectedIndex = 1;
设置代理
self.delegate = self;
代理方法
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
if (viewController == tabBarController.viewControllers[1]) {
return NO;
}
return YES;
}
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
NSLog(@"%ld",self.selectedIndex);
viewController.tabBarItem.badgeValue = nil;
}
- (void)tabBarController:(UITabBarController *)tabBarController willBeginCustomizingViewControllers:(NSArray *)viewControllers{
NSLog(@"将要开始编辑");
}
- (void)tabBarController:(UITabBarController *)tabBarController
willEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed{
NSLog(@"将要结束编辑more");
}
- (void)tabBarController:(UITabBarController *)tabBarController didEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed{
NSLog(@"已经结束编辑more");
}