博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[IOS]创建UITabBarController
阅读量:6358 次
发布时间:2019-06-23

本文共 1962 字,大约阅读时间需要 6 分钟。

创建若干个子视图控制器(并列关系)

创建UITabBarItem实例,赋值给相应的子视图控制器
创建一个数组,将已创建的子视图控制器添加到数组中
创建UITabBarController实例
tabBarController.viewControllers = viewControllers
添加到window的rootViewController中

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];    // Override point for customization after application launch.    self.window.backgroundColor = [UIColor whiteColor];    [self.window makeKeyAndVisible];        HomeViewController *ctrl1 = [[HomeViewController alloc]init];    UITabBarItem *homeItem = [[UITabBarItem alloc] initWithTitle:@"首页" image:[UIImage imageNamed: @""] tag:1];    ctrl1.tabBarItem = homeItem;        MessageViewController *ctrl2 = [[MessageViewController alloc]init];    UITabBarItem *msgItem = [[UITabBarItem alloc] initWithTitle:@"新闻" image:[UIImage imageNamed: @""] tag:2];    ctrl2.tabBarItem = msgItem;        HistoryViewController *ctrl3 = [[HistoryViewController alloc]init];    UITabBarItem *historyItem = [[UITabBarItem alloc] initWithTitle:@"历史" image:[UIImage imageNamed: @""] tag:3];    ctrl3.tabBarItem = historyItem;        SearchViewController *ctrl4 = [[SearchViewController alloc]init];    UITabBarItem *searchItem = [[UITabBarItem alloc] initWithTitle:@"搜索" image:[UIImage imageNamed: @""] tag:4];    ctrl4.tabBarItem = searchItem;        SettingViewController *ctrl5 = [[SettingViewController alloc]init];    UITabBarItem *settingItem = [[UITabBarItem alloc] initWithTitle:@"设置" image:[UIImage imageNamed: @""] tag:5];    ctrl5.tabBarItem = settingItem;        NSArray *controllers = @[ctrl1,ctrl2,ctrl3,ctrl4,ctrl5];        UITabBarController *tabController = [[UITabBarController alloc]init];    [tabController setViewControllers:controllers animated:YES];        self.window.rootViewController = tabController;        return YES;}

 

转载于:https://www.cnblogs.com/wisher/archive/2013/03/28/2987873.html

你可能感兴趣的文章
django 中文报错
查看>>
名片识别
查看>>
No Hibernate Session bound to thread...问题解决
查看>>
eclipse debug调试mapreduce程序
查看>>
boost链接错误
查看>>
zookeeper安装
查看>>
Linux下添加新硬盘,分区及挂载
查看>>
Preferences
查看>>
Openfire 用户离线、断线 及心跳检测
查看>>
JAVA反射机制
查看>>
Intent 跳转调用其他软件
查看>>
Android Ftp
查看>>
基于华为防火墙双机热备
查看>>
rsync 只拷贝 同步 指定的文件 filter规则
查看>>
浅谈grep和正则表达式的亲密接触
查看>>
zabbix监控nginx
查看>>
2015年天翊他爹有想法了
查看>>
java基础学习--排序算法
查看>>
我的友情链接
查看>>
阿狸fastjson
查看>>