tabbarController的使用

本文介绍了一个简单的TabBarController的实现步骤,包括创建标签控制器、创建相应的子控制器并设置导航栏标题等,最后添加到控制器中完成TabBarController的搭建。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

做一个简单的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];
这只是低级的实现方法 下一篇 封装

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

~轻舟~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值