Change only one specific UITabBarItem tint color

前端 未结 6 2146
猫巷女王i
猫巷女王i 2021-01-05 00:53

It is well known that the tint color of selected (or active) items in a UITabBarController can be easily changed, here is an example:

myBarController.tabBar.         


        
6条回答
  •  星月不相逢
    2021-01-05 01:31

    There is a much easier way to do this! Add this to the ViewController which UITabBar Item should be in another color

    - (void) viewWillAppear:(BOOL)animated {
       // change tint color to red
       [self.tabBarController.tabBar setTintColor:[UIColor redColor]];
       [super viewWillAppear: animated];
    }
    

    Insert this to the other ViewControllers

    - (void) viewWillAppear:(BOOL)animated {
       // change tint color to black
       [self.tabBarController.tabBar setTintColor:[UIColor blackColor]];
       [super viewWillAppear: animated];
    }
    

    I use this to get different Tint colors in each ViewController e.g.: [ red | black | green | pink ]

提交回复
热议问题