tabbarItem 怎么不显示?

今天是第一次写博客。我是一个博客新手,也是一个iOS开发新手。

我希望我自己写的东西,能够帮到像我一样的新手菜鸟。

创建了一个继承UItabbarcontroller的控制器

写完以下代码运行,发现模拟器上只有tabbar的背景图片,对应的Item项怎么没有显示?

//    文字

    NSArray * titleArray = @[@"首页",@"分类",@"购物车",@"我的账户"];

//    选中时的图片

    NSArray * selectedArray = @[@"tabbar_index",@"tabbar_cat",@"tabbar_cart",@"myaccount"];

//    未选中时的图片

    NSArray * unSelectedArray = @[@"tabbar_index",@"tabbar_cat",@"tabbar_cart",@"myaccount"];

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

//      读取每一项

        UITabBarItem * item = self.tabBar.items[i];    

//      bar使用图片需要经过处理才可以使用

        UIImage * selectedImage = [UIImage imageNamed:selectedArray[i]];

        selectedImage = [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

        UIImage * unSelectedImage = [UIImage imageNamed:unSelectedArray[i]];

        unSelectedImage = [unSelectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];  

        item = [item initWithTitle:titleArray[i] image:unSelectedImage selectedImage:selectedImage];

//      设置Item选中和未选中的颜色

        [item setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]} forState:UIControlStateNormal];

        [item setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]} forState:UIControlStateSelected];

    }

//   设置tabbar背景

    [self.tabBar setBackgroundImage:[UIImage imageNamed:@"tab_bg.jpg"]];

然后我咨询了一下一位正在参加iOS培训班的同学(刚好学到这一块了)。然而他给我的回答让我无法忍受,居然说我这个不就是自定义的tabbar嘛?自定义要把系统的隐藏,我就无语了,心想我这个就是系统的隐藏个毛线啊,然后,我又去百度了,没有搜到我想要的答案,不知道是不是我的搜索的关键词问题。那么言归正传,怎么才能让tabbar上面显示出Item呢?我想,是不是缺少类似容器什么的?果然添加下面的代码就可以了显示出Item了!

//    首页

    IndexViewController * vc1 = [[IndexViewController alloc]initWithNibName:nil bundle:nil];

    UINavigationController * nc1 = [[UINavigationController alloc]initWithRootViewController:vc1];

//    分类

    CategoryViewController * vc2 = [[CategoryViewController alloc]initWithNibName:nil bundle:nil];

    UINavigationController * nc2 = [[UINavigationController alloc]initWithRootViewController:vc2];

//    购物车

    ShoppingCarViewController * vc3 = [[ShoppingCarViewController alloc]initWithNibName:nil bundle:nil];

    UINavigationController * nc3 = [[UINavigationController alloc]initWithRootViewController:vc3];

//    我的账户

    MyAccountViewController * vc4 = [[MyAccountViewController alloc]initWithNibName:nil bundle:nil];

    UINavigationController * nc4 = [[UINavigationController alloc]initWithRootViewController:vc4];

    

self.viewControllers = @[nc1,nc2,nc3,nc4];

最后一句代码也许就是对应的属性。


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值