Reputation: 3600
I have a tab bar controller and I've managed to make the selected tab image and title black and the unselected item titles white but I can't get the unselected item images to be white.
In my tab bar controller: - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
UIColor *customColor = [UIColor colorWithRed:179.0/255.0f green:155.0/255.0f blue:107.0/255.0f alpha:1];
[self.tabBar setBarTintColor:customColor];
[self.tabBar setSelectedImageTintColor:[UIColor blackColor]];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor blackColor], NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor whiteColor], NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];
UITabBarItem *item0 = [self.tabBar.items objectAtIndex:0];
UITabBarItem *item1 = [self.tabBar.items objectAtIndex:1];
UITabBarItem *item2 = [self.tabBar.items objectAtIndex:2];
item0.image = [[UIImage imageNamed:@"home_unselected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
item0.selectedImage = [UIImage imageNamed:@"home_tab"];
item1.image = [[UIImage imageNamed:@"contact_unselected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
item1.selectedImage = [UIImage imageNamed:@"contact_tab"];
item2.image = [[UIImage imageNamed:@"about_unselected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
item2.selectedImage = [UIImage imageNamed:@"about_tab"];
}
Upvotes: 1
Views: 1062
Reputation: 3600
I got it working like this:
tab bar controller:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
UIColor *customColor = [UIColor colorWithRed:179.0/255.0f green:155.0/255.0f blue:107.0/255.0f alpha:1];
[self.tabBar setBarTintColor:customColor];
[self.tabBar setTintColor:[UIColor blackColor]];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor blackColor], NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor whiteColor], NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];
}
In each of the three view controllers on the tab bar:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
self.title = NSLocalizedString(@"Home", @"Home");
self.tabBarItem.image = [[UIImage imageNamed:@"home_unselected"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
self.tabBarItem.selectedImage = [UIImage imageNamed:@"home_tab"];
}
return self;
}
Upvotes: 1