标签:
- (void)addChildViewController:(UIViewController *)childController;
property(nonatomic,copy) NSArray *viewControllers;
1 //标题文字 2 @property(nonatomic,copy) NSString *title; 3 //图标 4 @property(nonatomic,retain) UIImage *image; 5 //选中时的图标 6 @property(nonatomic,retain) UIImage *selectedImage; 7 //提醒数字 8 @property(nonatomic,copy) NSString *badgeValue;
具体示例代码(在AppDelegate.m文件中):
1 //1.创建窗口 2 UIWindow *window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 3 4 //2.设置窗口的根控制器 为Tabbar控制器 5 6 // 2.1创建tabbar控制器 7 UITabBarController *tabbarVc = [[UITabBarController alloc] init]; 8 9 // 2.2设置子控制器 10 UIViewController *vc1 = [[UIViewController alloc] init]; 11 vc1.view.backgroundColor = [UIColor redColor]; 12 13 // 设置UITabbarButton的标题 14 vc1.tabBarItem.title = @"联系人"; 15 vc1.tabBarItem.image = [UIImage imageNamed:@"tab_buddy_nor"]; 16 vc1.tabBarItem.badgeValue = @"12"; 17 //[tabbarVc addChildViewController:vc1]; 18 19 UIViewController *vc2 = [[UIViewController alloc] init]; 20 vc2.view.backgroundColor = [UIColor greenColor]; 21 //[tabbarVc addChildViewController:vc2]; 22 vc2.tabBarItem.title = @"动态"; 23 vc2.tabBarItem.image = [UIImage imageNamed:@"tab_qworld_nor"]; 24 25 26 UIViewController *vc3 = [[UIViewController alloc] init]; 27 vc3.view.backgroundColor = [UIColor yellowColor]; 28 //[tabbarVc addChildViewController:vc3]; 29 vc3.tabBarItem.title = @"设置"; 30 vc3.tabBarItem.image = [UIImage imageNamed:@"tab_me_nor"]; 31 32 33 //一次性添加tabbar的子控制器 34 tabbarVc.viewControllers = @[vc1,vc2,vc3]; 35 //设置窗口的根控制器 36 window.rootViewController = tabbarVc; 37 38 // 3.设置窗口为主窗口并可见 39 [window makeKeyAndVisible]; 40 self.window = window;
最终效果:
标签:
原文地址:http://www.cnblogs.com/xiaomoge/p/4201389.html