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];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容