Question

I want to change the tintColor property according to tabbar's selected index. The code I'm using now is not working, all the tabbar views have this code:

- (void)viewDidAppear:(BOOL)animated{

    switch (self.tabBarController.selectedIndex) {
        case 0:
            self.tabBarController.tintColor = [UIColor colorWithRed:147/255 green:22/255 blue:0/255 alpha:1.0];
            break;

        case 1:
            self.tabBarController.tintColor = [UIColor whiteColor];
            break;

        case 2:
            self.tabBarController.tintColor = [UIColor greenColor];
            break;

        default:
            break;
    }
}
Was it helpful?

Solution

You don't need to do that; instead, put this in the viewWillAppear: method of your contained controllers:

Controller 1:

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.tintColor = [UIColor blueColor];
}

Controller 2:

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.tintColor = [UIColor yellowColor];
}

This assumes iOS5+. Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top