当前位置:网站首页>tabbarController的使用
tabbarController的使用
2022-07-26 09:22:00 【~轻舟~】
做一个简单的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];
这只是低级的实现方法 下一篇 封装
边栏推荐
猜你喜欢
随机推荐
Your login IP is not within the login mask configured by the administrator
Server memory failure prediction can actually do this!
Exception handling mechanism II
Sending and receiving of C serialport
神经网络与深度学习-6- 支持向量机1 -PyTorch
760. 字符串长度
[arkit, realitykit] turn pictures into 3D models
756. 蛇形矩阵
暑假第四周
“could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32” 问题处理
Innovus is stuck, prompting x error:
The essence of attack and defense strategy behind the noun of network security
Sliding window, double pointer, monotone queue, monotone stack
838. 堆排序
Study notes of dataX
【Flutter -- 布局】Align、Center、Padding 使用详解
Announcement | FISCO bcos v3.0-rc4 is released, and the new Max version can support massive transactions on the chain
When you click input, the border is not displayed!
Laravel框架日志文件存放在哪里?怎么用?
STM32+MFRC522完成IC卡号读取、密码修改、数据读写