关于UITabBarController的使用

作者: 懒得起名的伊凡 | 来源:发表于2015-08-19 13:52 被阅读272次

    先贴一下项目github地址

    问题一:

    UITabBarItem设置图片时候,经常会出现不能显示原本的图片显示的问题。
    还是直接上代码

    JYHomeViewController *homeViewController = [[JYHomeViewController alloc]init];
    UINavigationController *homeNav = [[UINavigationController alloc]initWithRootViewController:homeViewController];    JYMerchantViewController *merchantViewController = [[JYMerchantViewController alloc]init];
    UINavigationController *merchantNav = [[UINavigationController alloc]initWithRootViewController:merchantViewController];
    
    JYMiscViewController *miscViewController = [[JYMiscViewController alloc]init];
    UINavigationController *miscNav = [[UINavigationController alloc]initWithRootViewController:miscViewController];
    
    JYMineViewController *mineViewController = [[JYMineViewController alloc]init];
    UINavigationController *mineNav = [[UINavigationController alloc]initWithRootViewController:mineViewController];
    
    JYOnsiteViewController *onSiteViewController = [[JYOnsiteViewController alloc]init];
    UINavigationController *onSiteNav = [[UINavigationController alloc]initWithRootViewController:onSiteViewController];
    
    NSArray *tabBarViewControllers = @[homeNav,merchantNav,mineNav,miscNav,onSiteNav];
    
    self.viewControllers = tabBarViewControllers;
      
    UITabBarItem *tabBarItem0 = [self.tabBar.items objectAtIndex:0];
    UITabBarItem *tabBarItem1 = [self.tabBar.items objectAtIndex:1];
    UITabBarItem *tabBarItem2 = [self.tabBar.items objectAtIndex:2];
    UITabBarItem *tabBarItem3 = [self.tabBar.items objectAtIndex:3];
    UITabBarItem *tabBarItem4 = [self.tabBar.items objectAtIndex:4];
    
    /*!
     *  @author Yooeee
     *
     *  解释一下(解决了不显示原图,都是蓝色的问题):
     *
     *  UIImageRenderingModeAlwaysOriginal    draw the original image, without treating it as a template
     *
     *  UIImageRenderingModeAlwaysTemplate    Always draw the image as a template image, ignoring its color information
     */
    tabBarItem0.image = [[UIImage imageNamed:@"icon_tabbar_homepage"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    tabBarItem0.selectedImage = [[UIImage imageNamed:@"icon_tabbar_homepage_selected"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    tabBarItem0.title = @"首页";
    
    tabBarItem1.image = [[UIImage imageNamed:@"icon_tabbar_merchant_normal"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    tabBarItem1.selectedImage = [[UIImage imageNamed:@"icon_tabbar_merchant_selected"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    tabBarItem1.title = @"商家";
    
    tabBarItem2.image = [[UIImage imageNamed:@"icon_tabbar_onsite"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    tabBarItem2.selectedImage = [[UIImage imageNamed:@"icon_tabbar_onsite_selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    tabBarItem2.title = @"上门";
    
    tabBarItem3.image = [[UIImage imageNamed:@"icon_tabbar_mine"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    tabBarItem3.selectedImage = [[UIImage imageNamed:@"icon_tabbar_mine_selected"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    tabBarItem3.title = @"我的";
    
    tabBarItem4.image = [[UIImage imageNamed:@"icon_tabbar_misc"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    tabBarItem4.selectedImage = [[UIImage imageNamed:@"icon_tabbar_misc_selected"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    tabBarItem4.title = @"设置";
    
    /*!
     *  @author Yooeee
     *
     *  @brief  修改底部字体的颜色
     */
    [[UITabBarItem appearance]setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:41/255.0 green:173/255.0 blue:160/255.0 alpha:1.0]} forState:UIControlStateSelected];
    

    相关文章

      网友评论

      • dedenc:你好,我想问下 我的项目 在ios10系统下打开之后,底部的tabbar消失不见了 请问新特性有更改这个tabbar吗 我看了 方法也走了 也都有值,在10以下的系统都是没问题。10上就有问题, 我打印了下<UITabBar: 0x7fe7f857d300; frame = (0 667; 375 0); 不知道为什么高度是0 我是自己创建了一个TabBarViewController 继承自系统的,不知道什么原因变成了这个 而且我的上面的tabbar.items没有了,是nil? 请问你遇到过这个问题吗?
        凯文Kevin21:@dedenc 我的没有问题啊,也是这样创建的。。啊
      • 186d12ae8d63:作者绝逼写的是美团,学习了

      本文标题:关于UITabBarController的使用

      本文链接:https://www.haomeiwen.com/subject/xwhgqttx.html