UITabBarController(菜单栏)带导航栏的tabBar

 

1.定义:它能选择进入某个页面,通过一个数组里面存储的视图控制器。它也是一个ViewController。

2.初始化菜单栏:

//  菜单栏

    UITabBarController *tabbar = [[UITabBarController alloc]init];

    tabbar.tabBar.tintColor = [UIColor whiteColor];

    tabbar.viewControllers = @[group,news,user];

3.第二点中红字表示 tabbar 中包含的三个 ViewController,他们来自于:

    ViewController *group = [[ViewController alloc]init];

    NewsViewController *news = [[NewsViewController alloc]init]; 

    UserViewController *user = [[UserViewController alloc]init];

4.找到UITabBarController里面的 菜单栏视图 再找到里面的 tabBarItem 的数组 数组里面存的是 viewControllers 视图控制器的数组 对应的按钮

    NSArray *titleName = @[@"圈子",@"新闻",@"个人中心"];

    NSArray *photos  = @[@"12",@"444",@"333"];

  //  设置UITabBarItem的标题 

    for (int i = 0; i < title.count; i++) {  

        UITabBarItem *groupItem = tabbar.tabBar.items[i];

        groupItem.title = titleName [i];

        groupItem.image = [ UIImage imageNamed:photos[i] ];

    }

//   让tabbar默认选择在数组下标为1,也就是中间的位置。

    tabbar.selectedIndex = 1;

    

    self.window.rootViewController = tabbar; //让tabbar这个实例化出来的对象作为根视图控制器

    

    [self.window makeKeyAndVisible];


 带导航控制器的菜单栏   

使用方法:

 ViewController *group = [[ViewController alloc]init];

       UINavigationController *groups = [[UINavigationController alloc]initWithRootViewController:group];

  

    NewsViewController *news = [[NewsViewController alloc]init];

    UINavigationController *new = [[UINavigationController alloc]initWithRootViewController:news];

 

    UserViewController *user = [[UserViewController alloc]init];

    UINavigationController *use = [[UINavigationController alloc]initWithRootViewController:user];

    //  菜单栏

    UITabBarController *tabbar = [[UITabBarController alloc]init];

    tabbar.tabBar.tintColor = [UIColor whiteColor];

    tabbar.viewControllers = @[groups,new,use];


tabbar.viewControllers数组里面的内容变成了导航控制器的对象。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值