设置TabBar图片
// 拿到 TabBar 在拿到想应的item UITabBar *tabBar = _tabBarController.tabBar; UITabBarItem *item0 = [tabBar.items objectAtIndex:0]; UITabBarItem *item1 = [tabBar.items objectAtIndex:1]; UITabBarItem *item2 = [tabBar.items objectAtIndex:2]; UITabBarItem *item3 = [tabBar.items objectAtIndex:3]; // 对item设置相应地图片 item0.selectedImage = [[UIImage imageNamed:@"sy-1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];; item0.image = [[UIImage imageNamed:@"sy"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; item1.selectedImage = [[UIImage imageNamed:@"fl-1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];; item1.image = [[UIImage imageNamed:@"fl"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; item2.selectedImage = [[UIImage imageNamed:@"gwc-1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];; item2.image = [[UIImage imageNamed:@"gwc"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; item3.selectedImage = [[UIImage imageNamed:@"wd-1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];; item3.image = [[UIImage imageNamed:@"wd"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//设置tabbar图片和字体
MailViewController *mailVC = [[MailViewController alloc]init]; ClassViewController *classVC = [[ClassViewController alloc]init]; ShopcarViewController *shopcarVC = [[ShopcarViewController alloc]init]; MineViewController *mineVC = [[MineViewController alloc]init]; UITabBarController *tabbarvc = [[UITabBarController alloc]init]; tabbarvc.viewControllers = @[mailVC,classVC,shopcarVC,mineVC]; mailVC.tabBarItem.title = @"首页"; classVC.tabBarItem.title = @"分类"; shopcarVC.tabBarItem.title = @"购物车"; mineVC.tabBarItem.title = @"我的"; mailVC.tabBarItem.image = [UIImage imageNamed:@"sy@2x.jpg"]; classVC.tabBarItem.image = [UIImage imageNamed:@"fl@2x.jpg"]; shopcarVC.tabBarItem.image = [UIImage imageNamed:@"gwc@2x.jpg"]; mineVC.tabBarItem.image = [UIImage imageNamed:@"wd@2x.jpg"]; mailVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"sy01@2x.jpg"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; classVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"fl01@2x.jpg"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; shopcarVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"gwc01@2x.jpg"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; mineVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"wd01@2x.jpg"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; [mailVC.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:68/255.0 green:173/255.0 blue:50/255.0 alpha:1]} forState:UIControlStateSelected]; [classVC.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:68/255.0 green:173/255.0 blue:50/255.0 alpha:1]} forState:UIControlStateSelected]; [shopcarVC.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:68/255.0 green:173/255.0 blue:50/255.0 alpha:1]} forState:UIControlStateSelected]; [mineVC.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:68/255.0 green:173/255.0 blue:50/255.0 alpha:1]} forState:UIControlStateSelected]; self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds]; self.window.rootViewController = tabbarvc;