当前位置:网站首页>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];
这只是低级的实现方法 下一篇 封装
边栏推荐
猜你喜欢
What is the difference between NFT and digital collections?
volatile 靠的是MESI协议解决可见性问题?(下)
服务器内存故障预测居然可以这样做!
redis原理和使用-安装和分布式配置
Go intelligent robot alpha dog, alpha dog robot go
【Mysql】认识Mysql重要架构(一)
垂直搜索
Original root and NTT 5000 word explanation
Under a directory of ext3 file system, subfolders cannot be created, but files can be created
Redis principle and usage - installation and distributed configuration
随机推荐
Study notes of canal
大二上第二周学习笔记
Windows通过命令备份数据库到本地
Hbuilderx runs the wechat developer tool "fail to open ide" to solve the error
756. 蛇形矩阵
839. Simulation reactor
【Mysql】Mysql锁详解(三)
Basic use of ArcGIS 1
Innovus is stuck, prompting x error:
cocoapods的安装和使用
Arc GIS basic operation 3
安卓 实现缓存机制,多种数据类型缓存
微信小程序学习笔记2
Basic use of ArcGIS 4
JVM触发minor gc的条件
[MySQL] how to execute an SQL statement (2)
Error: Cannot find module ‘umi‘ 问题处理
垂直搜索
Canal 的学习笔记
NTT (fast number theory transformation) polynomial inverse 1500 word analysis