UITabBarController的使用
来源:互联网 发布:网络平台推广好做吗 编辑:程序博客网 时间:2024/05/16 18:06
一、简单介绍
UITabBarController和UINavigationController类似,UITabBarController也可以轻松地管理多个控制器,轻松完成控制器之间的切换,典型的例子就是QQ、微信等应⽤。
二、UITabBarController的使用
(1)初始化UITabBarController
(2)设置UIWindow的rootViewController为UITabBarController
(3)创建相应的子控制器(viewcontroller)
(4)把子控制器添加到UITabBarController
三、代码实例
#import "AppDelegate.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//1.创建Window
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]bounds]];
self.window.backgroundColor = [UIColor whiteColor];
//a.初始化一个tabBar控制器
UITabBarController *tb=[[UITabBarController alloc]init];
//设置控制器为Window的根控制器
self.window.rootViewController=tb;
//b.创建子控制器
UIViewController *c1=[[UIViewController alloc]init];
c1.view.backgroundColor=[UIColor greenColor];
c1.tabBarItem.title=@"消息";
c1.tabBarItem.image=[UIImage imageNamed:@"12.png"];
c1.tabBarItem.badgeValue=@"123";
UIViewController *c2=[[UIViewController alloc]init];
c2.view.backgroundColor=[UIColor orangeColor];
c2.tabBarItem.title=@"联系人";
UIViewController *c3=[[UIViewController alloc]init];
c3.tabBarItem.title=@"动态";
UIViewController *c4=[[UIViewController alloc]init];
c4.view.backgroundColor=[UIColor grayColor];
c4.tabBarItem.title=@"设置";
//c.添加子控制器到ITabBarController中
//c.1第一种方式
//[tb addChildViewController:c1];
//[tb addChildViewController:c2];
//[tb addChildViewController:c3];
//[tb addChildViewController:c4];
//c.2第二种方式
tb.viewControllers=@[c1,c3,c4,c2];
//2.设置Window为主窗口并显示出来
[self.window makeKeyAndVisible];
return YES;
}
结果:
三、重要说明
1.UITabBar
下方的工具条称为UITabBar,如果UITabBarController有N个子控制器,那么UITabBar内部就会有N个UITabBarButton作为子控件与之对应。
注意:UITabBarButton在UITabBar中得位置是均分的,UITabBar的高度为49。
在上面的程序中,UITabBarController有4个子控制器,所以UITabBar中有4个UITabBarButton。
2.UITabBarButton
UITabBarButton⾥面显⽰什么内容,由对应子控制器的tabBarItem属性来决定
3.有两种方式可以往UITabBarController中添加子控制器
(1)[tb addChildViewController:c1];
(2)tb.viewControllers=@[c1,c2,c3,c4];
注意:展示的顺序和添加的顺序一致,和导航控制器中不同,展现在眼前的是第一个添加的控制器对应的View。
- UITabBarController的使用总结
- UITabBarController的使用总结
- UITabBarController的使用总结
- UITabBarController的使用总结
- UITabBarController的简单使用
- UITabBarController的使用心得
- 关于UITabBarController的使用
- UITabBarController的使用步骤
- UITabBarController的使用
- UITabBarController的使用
- UITabBarController的简单使用
- UITabBarController简单的使用
- UITabBarController的使用
- UITabBarController的使用
- UITabBarController的使用(整理)
- ios--UITabBarController代理的使用
- 30.UITabBarController的基本使用
- IOS关于UITabBarController的使用
- IDEA快捷键使用技巧整理
- 关于ListView加入HeaderView之后,点击条目时获得position参数移位的BUG修正
- hadoop权威指南中的ncdc数据下载地址及命令
- [LeetCode][Database]Employees Earning More Than Their Managers
- 第五周项目四 静态成员应用
- UITabBarController的使用
- javascript读取本地文件
- page指令属性
- 快速排序QuickSort
- 【数据结构】图的遍历方法 深度优先遍历和广度优先遍历
- UINavigationController的使用
- Leetcode---Unique Binary Search Trees
- [推荐]ORACLE SQL:经典查询练手第二篇(不懂装懂,永世饭桶!)
- Android Handler机制