iOS开发--标签视图控制器--UITabBarController
2015-09-06 15:26
573 查看
UITabBarController也是和UINaVigationController一样是多视图控制器 ,但是他和导航视图控制器不太一样,在对视图控制器管理上 ,导航视图控制器通过push pop进行栈的管理 ,界面之间是有层级关系, 标签视图控制器 管理的视图控制器是并列存在的关系 我们通过点击不同的标签 进行不同界面的切换
在根视图控制器
//配置ViewControllers
-(void)configViewControllers{ //第一个 First *firstVC = [[[First alloc]init]autorelease]; //导航视图控制器 UINavigationController *firstNaVC = [[[UINavigationController alloc]initWithRootViewController:firstVC]autorelease]; // //设置导航栏title // firstVC.navigationItem.title = @"主页"; // //设置tabBar的title // firstNaVC.tabBarItem.title = @"first"; // 设置导航栏title和下面的导航title 等同于上面两步 firstVC.title = @"主页"; //设置tabBarItem图片 firstNaVC.tabBarItem.image = [UIImage imageNamed:@"53-house.png"]; //第二个 Second *SecondVC = [[[Second alloc]init]autorelease]; //导航视图控制器 UINavigationController *SecondNaVC = [[[UINavigationController alloc]initWithRootViewController:SecondVC]autorelease]; //设置导航栏title和下面的导航title SecondVC.title = @"海贼"; SecondNaVC.tabBarItem.image = [UIImage imageNamed:@"22-skull-n-crossbones.png"]; //第三个 Third *ThirdVC = [[[Third alloc]init]autorelease]; //导航视图控制器 UINavigationController *ThirdNaVC = [[[UINavigationController alloc]initWithRootViewController:ThirdVC]autorelease]; ThirdVC.title = @"电话"; ThirdNaVC.tabBarItem.image = [UIImage imageNamed:@"75-phone.png"]; //增加红点提示 ThirdNaVC.tabBarItem.badgeValue = @"99+"; Fourth *forthVC = [[[Fourth alloc]init]autorelease]; //导航视图控制器 UINavigationController *forthNaVC = [[[UINavigationController alloc]initWithRootViewController:forthVC]autorelease]; forthVC.title = @"百度"; forthNaVC.tabBarItem.image = [UIImage imageNamed:@"82-dogpaw.png"]; //第五个 Fiveth *fiveVC = [[[Fiveth alloc]init]autorelease]; //导航视图控制器 UINavigationController *fiveNaVC = [[[UINavigationController alloc]initWithRootViewController:fiveVC]autorelease]; fiveVC.title = @"爱"; fiveNaVC.tabBarItem.image = [UIImage imageNamed:@"29-heart.png"]; //设置 tabBarController 控制的视图控制器们 self.viewControllers = @[firstNaVC,SecondNaVC,ThirdNaVC,forthNaVC,fiveNaVC]; }
点击取消红点提示 (AppDelegate.m文件)
1:在 AppDelegate.m文件遵守 UITabBarControllerDelegate协议
2 : 设置代理
tabRootVC.delegate = self;
3:实现两个方法
//设置Controller对应的标签 是否可以点击 是否可以调换位置
-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{ return YES; }
设置TabBar
//tintcolor tabBar选中颜色 tabRootVC.tabBar.tintColor = [UIColor cyanColor]; //barTintColor tabBar背景 tabRootVC.tabBar.barTintColor = [UIColor blackColor]; //设置图片 必须给49高度 [tabRootVC.tabBar setBackgroundImage:[UIImage imageNamed:@"320x49.png"]];
相关文章推荐
- UISwitch(开关)
- true、false和1、0
- UIStepper(计数器)
- Arduino 控制超声波测距模块
- iOS开发UI -- UIAlertController(提示框)
- iOS开发UI -- 在storeBoard中通过标识符找到页面
- ctf很好的很详细的一篇guide
- UIPickerView隐藏黑线
- jboss无法自动创建Queue和Topic 发布时出现错误javax.naming.namenotfoundexception: myqueue not bound
- UIKit Dynamics 教程:抛掷 Views
- [LintCode]Segment Tree Query 线段树的查询
- Arduino控制继电器模块
- iOS 动画Animation详解, UIView动画,CALayer动画
- TBluetoothLE
- 一个共通的viewModel搞定所有的编辑页面-经典ERP录入页面(easyui + knockoutjs + mvc4.0)
- UIResponder - 2
- 获取UIColor中的RGB值(本人亲测多个获取RGB值的方法,这个最有效)
- iOS控件篇之——UILabel
- UITableView基本属性二:编辑模式
- HBuilder的几个常用快捷键