[tabBarC.tabBarsetSelectedImageTintColor:[UIColorwhiteColor]];
- (id)init
{
self = [super init];
if (self) {
// Custom initialization
self.tabBar.barStyle = UIBarStyleDefault;
self.tabBar.backgroundColor = [UIColorcolorWithHexString:@"#FFFFFF"alpha:1.0f];
self.tabBar.translucent = NO;
}
returnself;
}
+ (instancetype)tabBarC
{
SJBTabBarController *tabBarC = [[SJBTabBarControlleralloc] init];
HomeViewController *firstVC = [[HomeViewControlleralloc]initWithNibName:@"HomeViewController"bundle:nil];
RecommentViewController *secondVC = [[RecommentViewControlleralloc]initWithNibName:@"RecommentViewController"bundle:nil];
secondVC.isTabBarVC = YES;///额外添加的。
SJBMyCollectViewController *thirdVC = [[SJBMyCollectViewControlleralloc]init];
UINavigationController *naviFirstVC = [[UINavigationControlleralloc]initWithRootViewController:firstVC];
naviFirstVC.tabBarItem = [[UITabBarItemalloc] initWithTitle:@"全球地铁" image:[UIImageimageNamed:@"tab_home_normal"] selectedImage:[UIImage imageNamed:@"tab_home_select"]];
naviFirstVC.tabBarItem.tag = 0;
UINavigationController *naviSecondVC = [[UINavigationControlleralloc]initWithRootViewController:secondVC];
naviSecondVC.tabBarItem = [[UITabBarItemalloc] initWithTitle:@"世界旅行" image:[UIImageimageNamed:@"tab_travel_normal"] selectedImage:kImageNamed(@"tab_travel_select")];
naviSecondVC.tabBarItem.tag = 1;
UINavigationController *naviThirdVC = [[UINavigationControlleralloc]initWithRootViewController:thirdVC];
naviThirdVC.tabBarItem = [[UITabBarItemalloc] initWithTitle:@"我的收藏" image:[UIImageimageNamed:@"tab_collect_normal"] selectedImage:[UIImage imageNamed:@"tab_collect_select"]];
naviThirdVC.tabBarItem.tag = 2;
tabBarC.tabBar.clipsToBounds = YES;
[tabBarC setViewControllers:[NSMutableArray arrayWithObjects:naviFirstVC, naviSecondVC, naviThirdVC, nil]];
[tabBarC.tabBar setBackgroundImage:kImageNamed(@"tab_left_press")];
[tabBarC.tabBarsetSelectedImageTintColor:[UIColorwhiteColor]];
return tabBarC;
}
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
UINavigationController *navC = (UINavigationController *)viewController;
if ([navC.topViewController isKindOfClass:[HomeViewController class]]){
[tabBarController.tabBar setBackgroundImage:kImageNamed(@"tab_left_press")];
}elseif ([navC.topViewControllerisKindOfClass:[RecommentViewControllerclass]]){
[tabBarController.tabBar setBackgroundImage:kImageNamed(@"tab_middle_press")];
}else{
[tabBarController.tabBar setBackgroundImage:kImageNamed(@"tab_right_press")];
}
returnYES;
}