iOS-UITabBarController

重要思想:: TabBar 管理 Navigation, 然后 Navigation管理自己的界面(界面跳转)
注意::::: Navigation 中的 ViewControllers 数组是一个栈,一旦 pop 以后就没了,
但是 TabBar 中的 ViewControllers 数组不会消失.只是一个单纯的数组.

UITabBarControl:

    //显示第一个界面, 加入导航控制器
    MainViewController *mvc = [[MainViewController alloc] init];
    //设置title显示导航条上
    mvc.title = @"主界面";
    mvc.tabBarItem.image = [UIImage imageNamed:@"tab_0.png”];
    mvc.tabBarItem.badgeValue = @"999";
    
    //创建导航控制器, 让导航控制器管理mvc
    //  设置一个普通视图控制器作为根视图控制器
    UINavigationController *nc1 = [[UINavigationController alloc] initWithRootViewController:mvc];
    
    //创建第二个界面
    ContactsViewController *cvc = [[ContactsViewController alloc] init];
    cvc.title = @"联系人";
    cvc.tabBarItem.image = [UIImage imageNamed:@"tab_1.png"];
    UINavigationController *nc2 = [[UINavigationController alloc] initWithRootViewController:cvc];
    
    //第三个界面
    DynamicViewController *dvc = [[DynamicViewController alloc] init];
    dvc.title = @"动态";
    dvc.tabBarItem.image = [UIImage imageNamed:@"tab_2.png"];
    UINavigationController *nc3 = [[UINavigationController alloc] initWithRootViewController:dvc];
    
    //第四个界面
    SettingViewController *svc = [[SettingViewController alloc] init];
    svc.title = @"设置";
    svc.tabBarItem.image = [UIImage imageNamed:@"tab_3.png"];
    UINavigationController *nc4 = [[UINavigationController alloc] initWithRootViewController:svc];
    
    
    //创建标签栏
    UITabBarController *tbc = [[UITabBarController alloc] init];
    tbc.viewControllers = @[nc1,nc2,nc3,nc4];
    
    self.window.rootViewController = tbc;
    
    //标签栏默认高度49
    [tbc.tabBar setBackgroundImage:[UIImage imageNamed:@"tabbar.png"]];
    //设置选中的颜色
    tbc.tabBar.tintColor = [UIColor redColor];

你可能感兴趣的:(iOS-UITabBarController)