//实例化标签
UITabBarController * tabbarVC = [[UITabBarControlleralloc] init];
//修改tintColor
tabbarVC.tabBar.tintColor = [UIColorcyanColor];
//修改barTintColor
tabbarVC.tabBar.barTintColor = [UIColor orangeColor];
标签按钮实例化
UITabBarItem* item1 = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemDownloads tag:0];
标签右上数字显示方法
item1.badgeValue =
@"100";
给按钮添加图片以及点击后图片
UIImage * coll1 = [[UIImage imageNamed:@"tab_c1"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage * coll2 = [[UIImage imageNamed:@"tab_1"]
imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];//保持图片不被渲染吧
UITabBarItem * item3 = [[UITabBarItemalloc] initWithTitle:@"收藏" image:coll1selectedImage:coll2];
第一种添加子控制器的方法
//[tabbarVCaddChildViewController:vc1];
//[tabbarVCaddChildViewController:vc2];
//第二种添加子控制器的方法
tabbarVC.viewControllers = @[vc1,vc2,vc3,vc4,vc5];
设置tabbar为根控制器。
设置全局控件
UITabBar * tab =
[UITabBar appearance];
UITabBarItem * item =
[UITabBarItem appearance];
设置全局的tabbar
NSMutableArray *controllNames = [NSMutableArrayarrayWithArray:@[@"First",@"Second",@"Third"]];
NSArray * titles = @[@"第一页",@"第二页",@"第三页"];
for (NSUIntegeri = 0; i < controllNames.count; i++) {
//获取controller拼接后的名字
NSString* controllName = [controllNames[i]stringByAppendingString:@"ViewController"];
//将字符串转换成Class类型实例UIViewController
UIViewController * vc = [[NSClassFromString(controllName) alloc] init];
vc.title= titles[i];
BaseNavViewController * nav = [[BaseNavViewController alloc]initWithRootViewController:vc];
//根据索引值替换可变数组元素
[controllNames replaceObjectAtIndex:i withObject:nav];
}
self.viewControllers = controllNames;
当导航栏跳转时隐藏tabbar
vc.hidesBottomBarWhenPushed = YES;