当前位置:网站首页>TabbarController的封装
TabbarController的封装
2022-07-26 09:22:00 【~轻舟~】
首先建立一个类继承自UITabBarController
.m中实现代码:
- (void)viewDidLoad {
[super viewDidLoad];
ViewController *firstVc = [[ViewController alloc] init];
[self addChildVc:firstVc title:@"你好" image:@"mengmeng" selectedImage:@""];
SecondViewController *secondVc = [[SecondViewController alloc] init];
[self addChildVc:secondVc title:@"hello" image:@"jiyi" selectedImage:@""];
}
- (void)addChildVc:(UIViewController *)childVC title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
{
childVC.title = title;//同时设置tabBar和navgationBar的文字
//设置控制器的图片
childVC.tabBarItem.image = [UIImage imageNamed:image];
childVC.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
//设置导航控制器
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:childVC];
//添加为子控制器
[self addChildViewController:nav];
}
在AppDelegate中
self.window.rootViewController = [[QZTabBarController alloc] init];
就可以了
边栏推荐
猜你喜欢
Unity topdown character movement control
The Child and Binary Tree-多项式开根求逆
2022 Shanghai safety officer C certificate examination questions and mock examination
Study notes of canal
【线上问题】Timeout waiting for connection from pool 问题排查
【Mysql】redo log,undo log 和binlog详解(四)
Elastic APM安装和使用
Exception handling mechanism II
Windows通过命令备份数据库到本地
Innovus is stuck, prompting x error:
随机推荐
"Could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32"
Stm32+mfrc522 completes IC card number reading, password modification, data reading and writing
Li Mu D2L (V) -- multilayer perceptron
解决“NOTE: One or more layouts are missing the layout_width or layout_height attributes.”
Original root and NTT 5000 word explanation
Order based evaluation index (especially for recommendation system and multi label learning)
Go intelligent robot alpha dog, alpha dog robot go
Grain College of all learning source code
安卓 实现缓存机制,多种数据类型缓存
Exception handling mechanism II
【Mysql】认识Mysql重要架构(一)
Zipkin installation and use
Cat installation and use
字节缓冲流&字符流详解
Error: cannot find module 'UMI' problem handling
2022 Shanghai safety officer C certificate examination questions and mock examination
【Mysql】Mysql锁详解(三)
多项式开根
2022 chemical automation control instrument operation certificate test question simulation test platform operation
C# Serialport的发送和接收