[iOS基础控件 - 6.12.1] QQ菜单管理 UITabBarController 控制器管理
- 初始化UITabBarController
- 设置UIWindow的rootViewController为UITabBarController
- 根据具体情况,通过addChildViewController方法添加对应个数的子控制器
- 添加单个子控制器
- 设置子控制器数组
1 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 2 // Override point for customization after application launch. 3 4 // 设置window 5 self.window = [[UIWindow alloc] init]; 6 self.window.frame = [[UIScreen mainScreen] bounds]; 7 self.window.backgroundColor = [UIColor grayColor]; 8 [self.window makeKeyAndVisible]; 9 10 11 // 设置一个UITabBarController 12 UITabBarController *tabBarController = [[UITabBarController alloc] init]; 13 self.window.rootViewController = tabBarController; 14 15 // 添加子控制器 16 UIViewController *c1 = [[UIViewController alloc] init]; 17 c1.view.backgroundColor = [UIColor redColor]; 18 // [tabBarController addChildViewController:c1]; 19 20 UIViewController *c2 = [[UIViewController alloc] init]; 21 c2.view.backgroundColor = [UIColor blueColor]; 22 // [tabBarController addChildViewController:c2]; 23 24 UIViewController *c3 = [[UIViewController alloc] init]; 25 c3.view.backgroundColor = [UIColor greenColor]; 26 27 tabBarController.viewControllers = @[c1,c2,c3]; 28 29 30 return YES; 31 }
UITabBarItem有以下属性影响着UITabBarButton的内容
标题文字
@property(nonatomic,copy) NSString *title;
图标
@property(nonatomic,retain) UIImage *image;
选中时的图标
@property(nonatomic,retain) UIImage *selectedImage;
提醒数字
1 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 2 // Override point for customization after application launch. 3 4 // 设置window 5 self.window = [[UIWindow alloc] init]; 6 self.window.frame = [[UIScreen mainScreen] bounds]; 7 self.window.backgroundColor = [UIColor grayColor]; 8 [self.window makeKeyAndVisible]; 9 10 11 // 设置一个UITabBarController 12 UITabBarController *tabBarController = [[UITabBarController alloc] init]; 13 self.window.rootViewController = tabBarController; 14 15 // 添加子控制器 16 UIViewController *c1 = [[UIViewController alloc] init]; 17 c1.view.backgroundColor = [UIColor redColor]; 18 c1.tabBarItem.title = @"红色"; 19 // [tabBarController addChildViewController:c1]; 20 21 UIViewController *c2 = [[UIViewController alloc] init]; 22 c2.view.backgroundColor = [UIColor blueColor]; 23 c2.tabBarItem.title = @"蓝色"; 24 // [tabBarController addChildViewController:c2]; 25 26 UIViewController *c3 = [[UIViewController alloc] init]; 27 c3.view.backgroundColor = [UIColor greenColor]; 28 c3.tabBarItem.title = @"绿色"; 29 30 tabBarController.viewControllers = @[c1,c2,c3]; 31 32 33 return YES; 34 }
1 - (void)viewDidLoad { 2 [super viewDidLoad]; 3 NSLog(@"%@ - viewDidLoad", self.class); 4 } 5 6 - (void)viewWillAppear:(BOOL)animated { 7 [super viewWillAppear:animated]; 8 NSLog(@"%@ - viewWillAppear", self.class); 9 } 10 11 - (void)viewDidAppear:(BOOL)animated { 12 [super viewDidAppear:animated]; 13 NSLog(@"%@ - viewDidAppear", self.class); 14 } 15 16 - (void) viewWillDisappear:(BOOL)animated { 17 [super viewWillDisappear:animated]; 18 NSLog(@"%@ - viewWillDisappear", self.class); 19 } 20 21 - (void)viewDidDisappear:(BOOL)animated { 22 [super viewDidDisappear:animated]; 23 NSLog(@"%@ - viewDidDisappear", self.class); 24 } 25 26 27 - (void)didReceiveMemoryWarning { 28 [super didReceiveMemoryWarning]; 29 NSLog(@"%@ - didReceiveMemoryWarning", self.class); 30 } 31 32 - (void)viewWillUnload { 33 [super viewWillUnload]; 34 NSLog(@"%@ - viewWillUnload", self.class); 35 } 36 37 - (void)viewDidUnload { 38 [super viewDidUnload]; 39 NSLog(@"%@ - viewDidUnload", self.class); 40 }
2014-12-27 21:11:44.340 UITabBarControllerByStoryboard[22567:590996] OneViewController - viewWillAppear
2014-12-27 21:12:10.042 UITabBarControllerByStoryboard[22567:590996] TwoViewController - viewWillAppear
2014-12-27 21:12:10.042 UITabBarControllerByStoryboard[22567:590996] OneViewController - viewWillDisappear
2014-12-27 21:12:10.054 UITabBarControllerByStoryboard[22567:590996] OneViewController - viewDidDisappear
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。