Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

styling tab bar icons

While going through the styling tutorials, your code suggests using the following method to make sure that the selected icons on the tab bar stay white :

UITabBar * tabBar = tabBarcontroller.tabBar;

UITabBarItem * tabInbox = [tabBar.items objectAtIndex:0];

[tabInbox setFinishedSelectedImage:[UIImage imageNamed:@"inbox"] withFinishedUnselectedImage:[UIImage imageNamed:@"inbox"]];

However, it appears that the setFinishedSelectedImage method is now deprecated. xCode suggests using the initWithTitle method, which I did :

[tabInbox initWithTitle:@"Inbox" image:[UIImage imageNamed:@"inbox"] selectedImage:[UIImage imageNamed:@"inbox"]];

unfortunately, this doesn't get rid of the grey over the white icons like the deprecated method does. I would love any leads on how to properly implement this functionality without using deprecated methods.

thank you, Marina

Stone Preston
Stone Preston
42,016 Points

is there not two different images? I would think there would be a white one for unselected and grey for selected, but it appears you are using the same image for both selected and unselected

2 Answers

Enara L. Otaegi
Enara L. Otaegi
13,107 Points

Hi, I just discovered how to do this and works fine for me. Hope it works for you, too.

//Customize Tab bar [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];

UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UITabBar *tabBar = tabBarController.tabBar;

UIImage *inboxImage = [[UIImage imageNamed:@"inbox"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage *friendsImage = [[UIImage imageNamed:@"friends"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage *cameraImage = [[UIImage imageNamed:@"camera"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

UITabBarItem *tabInbox = [tabBar.items objectAtIndex:0];
UITabBarItem *tabFriends = [tabBar.items objectAtIndex:1];
UITabBarItem *tabCamera = [tabBar.items objectAtIndex:2];

tabInbox = [tabInbox initWithTitle:@"inbox" image:inboxImage selectedImage:inboxImage];
tabFriends = [tabFriends initWithTitle:@"friends" image:friendsImage selectedImage:friendsImage];
tabCamera = [tabCamera initWithTitle:@"camera" image:cameraImage selectedImage:cameraImage];
Stone Preston
Stone Preston
42,016 Points

awesome! thanks for sharing this.

:) thanks! that just help me out too! Ben Jakuben should update this issue in the notes section in the video

Jonathan Fernandez
Jonathan Fernandez
8,325 Points

Thanks so much for sharing this.. Awesome stuff and glad to learn from it! : D

Enara L. Otaegi
Enara L. Otaegi
13,107 Points

Thank you! I'm glad to see that this is helping :)

Huzzah, I would also like to jump on the thank you wagon! T'was stumped, and now I am un-stumped! Bravo!

Enara L. Otaegi
Enara L. Otaegi
13,107 Points

I'm glad that it helped you get unstumped :)