ios--UITabBarController的用法
来源:互联网 发布:东方财富股票交易软件 编辑:程序博客网 时间:2024/05/17 22:10
课堂实例2
完善实例1
(1)自定义一个UITabBarController实例,在此类中添加若干个视图控制器
(2)添加代理方法,查看当前的那一个视图控制器
(3) 是这自定义一个TabBarItem图片
代码如下:
AppDelegate.m中的代码
/*思路: *1.创建若干个子视图控制器(它们是并列的关系) * 1.1创建UITabBarItem实例,赋值给相应的子视图控制器(2中方法) *2.创建一个数组,将已创建的子视图控制器,添加到数组中 *3.创建UITabBarController实例 *4.tabBarController.viewControllers = viewControllers; *5.添加到window的rootViewController中(显示出来) */ homeViewController *vc1 = [[homeViewController alloc]init]; UITabBarItem *homeItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:1]; vc1.tabBarItem = homeItem; //vc1.title = @"首页"; //vc1.view.backgroundColor = [UIColor redColor]; MesageViewController *vc2 = [[MesageViewController alloc]init]; UITabBarItem *msmItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemContacts tag:2]; vc2.tabBarItem = msmItem; //vc2.title = @"新闻"; // vc2.view.backgroundColor = [UIColor blueColor]; SearchViewController *vc3 = [[SearchViewController alloc]init]; UITabBarItem *sacItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemHistory tag:3]; vc3.tabBarItem = sacItem; //vc3.title = @"历史"; //vc3.view.backgroundColor = [UIColor grayColor]; settingViewController *vc4 = [[settingViewController alloc]init]; UITabBarItem *setItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemMore tag:4]; vc4.tabBarItem = setItem; //vc4.title = @"搜索"; //vc4.view.backgroundColor = [UIColor yellowColor]; NSArray *viewControllers = @[vc1,vc2,vc3,vc4];//把他们放在数组中 UITabBarController *tabBarController = [[UITabBarController alloc]init]; //初始化 [tabBarController setViewControllers:viewControllers animated:YES]; self.window.rootViewController = tabBarController;homeViewController.m的代码:
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization self.title = @"首页"; } return self;}-(void)loadView{ UIView *view = [[UIView alloc]initWithFrame:[[UIScreen mainScreen] applicationFrame]]; view.backgroundColor = [UIColor redColor]; self.view = view;}MessageViewController.m中的代码:
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { self.title = @"新闻"; // Custom initialization } return self;}-(void)loadView{ UIView *view = [[UIView alloc]initWithFrame:[[UIScreen mainScreen] applicationFrame]]; view.backgroundColor = [UIColor greenColor]; self.view = view;}SearchViewController.m中的代码:
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { self.title = @"搜索"; // Custom initialization } return self;}-(void)loadView{ UIView *view = [[UIView alloc]initWithFrame:[[UIScreen mainScreen] applicationFrame]]; view.backgroundColor = [UIColor blueColor]; self.view = view;}SettingViewController.m中的代码:
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { self.title = @"设置"; // Custom initialization } return self;}-(void)loadView{ UIView *view = [[UIView alloc]initWithFrame:[[UIScreen mainScreen] applicationFrame]]; view.backgroundColor = [UIColor yellowColor]; self.view = view;}模拟器显示如图:
0 0
- ios--UITabBarController的用法
- iOS中UITabbarController的用法
- ios--UITabBarController的基本用法3
- ios--UITabBarController基本用法1
- 设置UITabBarController的用法
- ios学习笔记(5)UITabBarController用法
- ios--UITabBarController的层次关系
- ios--UITabBarController代理的使用
- iOS-UITabBarController的学习
- IOS关于UITabBarController的使用
- iOS中UITabBarController的剖析
- iOS UITabBarController 的 UITabBar 自定义
- iOS UITabbarController 屌屌的
- 【iOS开发-UITabBarController】UITabBarController上面的UINavigationController的设置
- UITabBarController用法
- UITabBarController用法
- UITabBarController用法
- ios UITabBarController
- BOJ 2014新生暑假个人排位赛07 整合
- LA 6662 —— The Last Ant(模拟)
- Hibernate对视图的映射
- 【Agile Pair Coding】Data Type Mapping
- hdoj 2087 剪花布条
- ios--UITabBarController的用法
- iocp详解
- OC 中的数组方法(不可变数组NSArray 和 可变数组 NSMutableArray)
- linux高级技巧:集群之keepalived
- 什么是sharding与切分
- HalconVC异常处理
- 逻辑地址、线性地址、物理地址和虚拟地址理解
- poj2115--C Looooops(扩展gcd)
- android 删除目录(实例)