[TwistedFate]TabBarController
2015-12-02 21:38
435 查看
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的背景图片
// tabBar高度49 self.tabBar.backgroundImage = [UIImage imageNamed:@"tabBar"];
设置默认选中的页面
self.selectedIndex = 1;
设置代理
self.delegate = self;
代理方法
// 设置不允许点击 - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{ // 可以指定哪个控制器不让点击 // 先取出 不让点击的控制器 if (viewController == tabBarController.viewControllers[1]) { // 如果选中的控制器是你不想让用户点击的 那么返回NO return NO; } return YES; } // 选中页面时触发的方法 - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{ // 打印选中的索引 NSLog(@"%ld",self.selectedIndex); // 选中时把红点去掉 viewController.tabBarItem.badgeValue = nil; } // 控制more的代理方法 - (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"); }
相关文章推荐
- 8、String to Integer (atoi)
- scala None null Nil的说明
- BZOJ 1012:[JSOI2008]最大数 maxnumber
- socket通讯原理以及tcp、ip三次握手机制学习
- IronPython for ASP.NET 部署注意事项
- jQuery基础选择器
- 思维导图 JAVA 语法基础
- Http中的get和post的区别
- 并集、交集、差集的概念
- oracle触发器调试
- 监听系统软键盘的显示与隐藏
- hdu1728逃离迷宫【深搜数量大小剪枝】
- WIN7下通过命令调用“控制面板项” / RUNDLL32详解 / CPL文件详解
- 理解 RPO 与 RTO
- tomcat服务器发布网站的方式小结
- 继承
- (二十三)变量名的命名
- (二十二)第二章最后的编程练习答案(七合一版)
- private, public, protected 访问标号的访问范围之JAVA篇
- SparkSQL样例