iOS 底部 tabbar详解 及 UITabBarButton 详解


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.csdn.net/lgm252008/article/details/9151157

IOS两种方式制作tabBar底部标签栏目

  1. 第一种方式:  
  2.   
  3.      //tabBar1添加  
  4.      NewsViewController *news = [[NewsViewController alloc] init];  
  5.      UINavViewController *nc1 = [[UINavViewController alloc] initWithRootViewController:news];  
  6.      nc1.tabBarItem.title = @"栏目1";  
  7.      nc1.tabBarItem.image = [UIImage imageNamed:@"menu_icon_main.png"];  
  8.      [nc1.tabBarItem.title sizeWithFont:[UIFont systemFontOfSize:20]];  
  9.      [news release];  
  10.   
  11.      //tabBar2添加  
  12.      NewsViewController *news2 = [[NewsViewController alloc] init];  
  13.      UINavViewController *nc2 = [[UINavViewController alloc] initWithRootViewController:news2];  
  14.      nc2.tabBarItem.title = @"栏目2";  
  15.      nc2.tabBarItem.image = [UIImage imageNamed:@"menu_icon_main.png"];  
  16.      [nc2.tabBarItem.title sizeWithFont:[UIFont systemFontOfSize:20]];  
  17.      [news2 release];  
  18.   
  19.   
  20.   ....  
  21.   
  22.   
  23.   
  24. NSArray *item = [NSArray arrayWithObjects:nc1,nc2, nil];  //最多可添加5个栏目   
  25.  UITabBarController *tabBar = [[UITabBarController alloc] init];  
  26.  [tabBar setDelegate:self];  
  27.   
  28.      [tabBar setViewControllers:item];  
  29.   
  30.      [self.window setRootViewController:tabBar];  
  31.   
  32.      [tabBar release];  
  33.   
  34.        
  35.   
  36.      [nc1 release];  
  37.   
  38.      [nc2 release]  
  39.   
  40. 第二种方式跟第一种方式稍有所不同  
  41.   
  42.      //tabBar1添加  
  43.      NewsViewController *news = [[NewsViewController alloc] init];  
  44.      UINavViewController *nc1 = [[UINavViewController alloc] initWithRootViewController:news];  
  45.      [nc1.tabBarItem.title sizeWithFont:[UIFont systemFontOfSize:20]];  
  46.      [news release];  
  47.   
  48.      //tabBar2添加  
  49.   
  50.      NewsViewController *news2 = [[NewsViewController alloc] init];  
  51.      UINavViewController *nc2 = [[UINavViewController alloc] initWithRootViewController:news2];  
  52.      nc2.tabBarItem.title = @"栏目2";  
  53.      nc2.tabBarItem.image = [UIImage imageNamed:@"menu_icon_main.png"];  
  54.      [nc2.tabBarItem.title sizeWithFont:[UIFont systemFontOfSize:20]];  
  55.      [news2 release];  
  56.   
  57.   ......  
  58.   
  59.      NSArray *item = [NSArray arrayWithObjects:nc1,nc2, nil];  //最多可添加5个栏目    
  60.      UITabBarController *tabBar = [[UITabBarController alloc] init];  
  61.      UIImageView *tabImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tabbarbg_app.png"]];  
  62.      [tabImgView setFrame:CGRectMake(0, 436, 320, 44)];      
  63.      tabBar.tabBar.backgroundImage = [UIImage imageNamed:@"tabbarbg_app.png"];//将栏目名字和栏目标识直接放在一张背景图上  
  64.      [tabBar setDelegate:self];  
  65.      [tabBar setViewControllers:item];  
  66.      [self.window setRootViewController:tabBar];  
  67.      [tabBar release];  
  68.        
  69.      [nc1 release];  
  70.      [nc2 release]; 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值