1.UITabBar
下方的工具条称为UITabBar ,如果UITabBarController有N个子控制器,那么UITabBar内部就会有N 个UITabBarButton作为子控件与之对应。
UITabBarButton在UITabBar中得位置是均分的,UITabBar的高度为49。
在上面的程序中,UITabBarController有4个子控制器,所以UITabBar中有4个UITabBarButton,UITabBar的结构⼤大致如下图所示:

2.UITabBarButton
UITabBarButton⾥面显⽰什么内容,由对应子控制器的tabBarItem属性来决定
c1.tabBarItem.title=; c1.tabBarItem.image=[UIImage imageNamed:tab_recent_nor];

3.有两种方式可以往UITabBarController中添加子控制器
(1)[tb addChildViewController:c1];
(2)tb.viewControllers=@[c1,c2,c3,c4];
展示的顺序和添加的顺序一致,和导航控制器中不同,展现在眼前的是第一个添加的控制器对应的View。
http://blog.youkuaiyun.com/lgm252008/article/details/9151157
- 第一种方式:
- //tabBar1添加
- NewsViewController *news = [[NewsViewController alloc] init];
- UINavViewController *nc1 = [[UINavViewController alloc] initWithRootViewController:news];
- nc1.tabBarItem.title = @"栏目1";
- nc1.tabBarItem.image = [UIImage imageNamed:@"menu_icon_main.png"];
- [nc1.tabBarItem.title sizeWithFont:[UIFont systemFontOfSize:20]];
- [news release];
- //tabBar2添加
- NewsViewController *news2 = [[NewsViewController alloc] init];
- UINavViewController *nc2 = [[UINavViewController alloc] initWithRootViewController:news2];
- nc2.tabBarItem.title = @"栏目2";
- nc2.tabBarItem.image = [UIImage imageNamed:@"menu_icon_main.png"];
- [nc2.tabBarItem.title sizeWithFont:[UIFont systemFontOfSize:20]];
- [news2 release];
- ....
- NSArray *item = [NSArray arrayWithObjects:nc1,nc2, nil]; //最多可添加5个栏目
- UITabBarController *tabBar = [[UITabBarController alloc] init];
- [tabBar setDelegate:self];
- [tabBar setViewControllers:item];
- [self.window setRootViewController:tabBar];
- [tabBar release];
- [nc1 release];
- [nc2 release]
- 第二种方式跟第一种方式稍有所不同
- //tabBar1添加
- NewsViewController *news = [[NewsViewController alloc] init];
- UINavViewController *nc1 = [[UINavViewController alloc] initWithRootViewController:news];
- [nc1.tabBarItem.title sizeWithFont:[UIFont systemFontOfSize:20]];
- [news release];
- //tabBar2添加
- NewsViewController *news2 = [[NewsViewController alloc] init];
- UINavViewController *nc2 = [[UINavViewController alloc] initWithRootViewController:news2];
- nc2.tabBarItem.title = @"栏目2";
- nc2.tabBarItem.image = [UIImage imageNamed:@"menu_icon_main.png"];
- [nc2.tabBarItem.title sizeWithFont:[UIFont systemFontOfSize:20]];
- [news2 release];
- ......
- NSArray *item = [NSArray arrayWithObjects:nc1,nc2, nil]; //最多可添加5个栏目
- UITabBarController *tabBar = [[UITabBarController alloc] init];
- UIImageView *tabImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tabbarbg_app.png"]];
- [tabImgView setFrame:CGRectMake(0, 436, 320, 44)];
- tabBar.tabBar.backgroundImage = [UIImage imageNamed:@"tabbarbg_app.png"];//将栏目名字和栏目标识直接放在一张背景图上
- [tabBar setDelegate:self];
- [tabBar setViewControllers:item];
- [self.window setRootViewController:tabBar];
- [tabBar release];
- [nc1 release];
- [nc2 release];