当我使用单个代码中的以下代码时,UITabBar外观不能完全正常工作(根本不会改变),并且UINavigationBar外观正在任意改变,而不是根据切换情况。
#pragma mark - UITabBarController Delegate
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
NSLog(@"switch");
switch ([tabBarController.viewControllers indexOfObject:viewController])
{
case 0:
[[UINavigationBar appearance] setBackgroundImage:[UIColor imageWithColor:[AppConfiguration color3]] forBarMetrics:UIBarMetricsDefault];
[[UITabBar appearance] setBarTintColor:[AppConfiguration color3]];
break;
case 1:
[[UINavigationBar appearance] setBackgroundImage:[UIColor imageWithColor:[AppConfiguration color4]] forBarMetrics:UIBarMetricsDefault];
[[UITabBar appearance] setBarTintColor:[AppConfiguration color4]];
break;
case 2:
[[UINavigationBar appearance] setBackgroundImage:[UIColor imageWithColor:[AppConfiguration color5]] forBarMetrics:UIBarMetricsDefault];
[[UITabBar appearance] setBarTintColor:[AppConfiguration color5]];
break;
default:
NSLog(@"UITabBar index: %lu", (unsigned long)[tabBarController.viewControllers indexOfObject:viewController]);
break;
}
}