对UITabBarController的理解

理解:和UINavigationController一样,UITabBarController也可以控制多个页面导航。用户可以在多个视图控制器之间移动,并可以定制屏幕底部的选项卡栏。

    UITabBarController是组建一系列的控制器,可以是UIViewController,UITableViewController,UINavigationController等,并将它们添加到选项卡栏,使每一个选项卡对应一个控制器。UINavigationController是以栈的形式将视图推入推出。UITabbarController一般作为appDelegate的根rootController使用。

分析图:


  事例:
.h中,

方法一只能适用于iOS5以下的系统,在iOS5+上面无法使用,所以必须把这两种方法结合起来,当使用viewController.hidesBottomBarWhenPushed = YES,然后再加上@interface TabBarAppDelegate : UIResponder <UIApplicationDelegate >


@property (strong, nonatomic) UIWindow *window;

@property (strong, nonatomic) TabBarViewController * tabbarController;

.m中,

    AViewController *aController = [[AViewController alloc] init];

    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:aController];

     //aController.title = @"aa";

    BViewController *bController = [[BViewController alloc] init];

   // bController.title = @"bb";

    CViewController *cController = [[CViewController alloc] init];

   // cController.title = @"cc";

    DViewController *dController = [[DViewController alloc] init];

   // dController.title = @"dd";

 _tabbarController = [[TabBarViewController alloc] initWithNibName:@"TabBarViewController" bundle:nil];

    _tabbarController.viewControllers = [NSArray arrayWithObjects:nav,bController,cController,dController, nil];

 //设置tabbar

//适合ios5以下

UIImageView *tabbarGroundImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mainbar_bg.png"]];

    [tabbarGroundImage setFrame:CGRectMake(0,0, self.tabBar.frame.size.width, self.tabBar.frame.size.height)];

    //ios5以下使用

    [self.tabBar insertSubview:tabbarGroundImage atIndex:0];

    [tabbarGroundImage release];


   //适和ios5以上

    [_tabbarController.tabBar setBackgroundImage:[UIImage imageNamed:@"mainbar_bg.png"]];

    UITabBarItem *aTabbar = [[UITabBarItem alloc] initWithTitle:nil image:[UIImage imageNamed:@"mainbar_icon1_n.png"] tag:0];

     [aTabbar setFinishedSelectedImage:[UIImage imageNamed:@"mainbar_icon1_d.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"mainbar_icon1_h.png"]];

    aController.tabBarItem = aTabbar;

    [aTabbar release];

    

    [aController release];

    [nav release];

    [bController release];

    [cController release];

    [dController release];

    self.window.rootViewController = _tabbarController;


注:用TabbarController上的tabbar,backGroundImage和tabbarItem上的image都是不能改变大小的,所以对切图要求很高。
//push到第二页的时候需要隐藏掉tabbar。方法:

 EViewController *eController = [[EViewController alloc] initWithNibName:@"EViewController" bundle:nil];

//在push之前加上这句话,放可管用。

     eController.hidesBottomBarWhenPushed = YES;

    [self.navigationController pushViewController:eController animated:YES];

    [eController release];






总结:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值