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

第一种方式:

     //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];

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值