关于UITabBarController的使用

先贴一下项目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];

推荐阅读更多精彩内容