做一个简单的tabbarController大体分为三步:
//1.创建标签控制器
UITabBarController *tab = [[UITabBarController alloc] init];
//2.创建相应的字控制器
ViewController *firstVc = [[ViewController alloc] init];
firstVc.tabBarItem.title = @"你好";
firstVc.tabBarItem.image = [UIImage imageNamed:@"萌萌"];
SecondViewController *secondVC = [[SecondViewController alloc] init];
secondVC.tabBarItem.title = @"hello";
secondVC.tabBarItem.image = UIImageName(@"记忆");
//3.添加到控制器
NSArray *array = @[firstVc,secondVC];
tab.viewControllers = array;
self.window.rootViewController = tab;
[self.window makeKeyAndVisible];
这样的话,一个简单的tabbarController就出来了
一般呢有Tabbar也会带有navgationBar所以今天我也将navgationbar也加上吧 看下面的代码:
//1.创建标签控制器
UITabBarController *tab = [[UITabBarController alloc] init];
//2.创建相应的字控制器
ViewController *firstVc = [[ViewController alloc] init];
//2.1这里加了nav的title
firstVc.navigationItem.title = @"你好";
firstVc.tabBarItem.title = @"你好";
firstVc.tabBarItem.image = [UIImage imageNamed:@"萌萌"];
//2.2这里初始化nav且设置rootVC
UINavigationController *firstNav = [[UINavigationController alloc] initWithRootViewController:firstVc];
SecondViewController *secondVC = [[SecondViewController alloc] init];
secondVC.navigationItem.title = @"hello";
secondVC.tabBarItem.title = @"hello";
secondVC.tabBarItem.image = UIImageName(@"记忆");
UINavigationController *secondNav = [[UINavigationController alloc] initWithRootViewController:secondVC];
//3.添加到控制器
//特别注意:管理一组的控制器(最多显示五个,多于五个的包括五个全部在更多模块,并且可以通过拖拽的方式进行顺序编辑);
// NSArray *array = @[firstVc,secondVC];
//将数组中的控制器换掉 就搞定了
NSArray *array = @[firstNav,secondNav];
tab.viewControllers = array;
self.window.rootViewController = tab;
[self.window makeKeyAndVisible];
这只是低级的实现方法 下一篇 封装