Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Implementing Designs for iPhone Customizing Table View Controllers Styling the Tab Bar

Tareq Alothman
Tareq Alothman
17,921 Points

When customizing TabBar setFinishedSelectedImage is deprecated! Could you please post notes on how to work around this?

Note to teacher Ben Jakuben! iOs Building Self Destructing Messaging App!

3 Answers

Stone Preston
Stone Preston
42,016 Points

you can use something like this instead:

the following allows you to set the image and selectedImage for each tab bar item. In this case, I set the image and selectedImage to be the same, but if you wanted to use a different selected image you could.

 //customize UITabBar Items
    UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
    UITabBar *tabBar = tabBarController.tabBar;
    UITabBarItem *tabInbox = [tabBar.items objectAtIndex:0];
    UITabBarItem *tabCamera = [tabBar.items objectAtIndex:1];
    UITabBarItem *tabFriends = [tabBar.items objectAtIndex:2];


    UIImage *inboxIconImage = [[UIImage imageNamed:@"inboxIcon"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage *cameraIconImage = [[UIImage imageNamed:@"cameraIcon"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage *friendsIconImage = [[UIImage imageNamed:@"friendsIcon"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];


    tabInbox = [tabInbox initWithTitle:nil image:inboxIconImage selectedImage:inboxIconImage];
    tabCamera = [tabCamera initWithTitle:nil image:cameraIconImage selectedImage:cameraIconImage];
    tabFriends = [tabFriends initWithTitle:nil image:friendsIconImage selectedImage:friendsIconImage];
Tareq Alothman
Tareq Alothman
17,921 Points

Thank you Stone for your quick answer, i did not understand the use of (tabSpots, tabMap, tabAdd) so here is my modified solution that did the trick for me!

UIImage *inboxIconImage = [[UIImage imageNamed:@"inbox"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage *friendsIconImage = [[UIImage imageNamed:@"friends"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage *cameraIconImage = [[UIImage imageNamed:@"camera"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

[tabInbox setImage:inboxIconImage];
[tabInbox setSelectedImage:inboxIconImage];
[tabFriends setImage:friendsIconImage];
[tabFriends setSelectedImage:friendsIconImage];
[tabInCamera setImage:cameraIconImage];
[tabCamera setSelectedImage:cameraIconImage];
Stone Preston
Stone Preston
42,016 Points

woops sorry. I copied and pasted from an app I made previously and forgot to change those variable names there. its fixed now

Benjamin McMahan
Benjamin McMahan
6,679 Points

THANK YOU!! This worked great. Was struggling trying to get fix everything. Really need a Teacher's Note for this with correct code.

Ericson Ortega
Ericson Ortega
3,307 Points

Hi Stone,

I can't seem to fix the tab bar text to show up can you check my code? TIA

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

UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UITabBar *tabBar = tabBarController.tabBar;
UITabBarItem *tabInbox = [tabBar.items objectAtIndex:0];
UITabBarItem *tabFriends = [tabBar.items objectAtIndex:1];
UITabBarItem *tabCamera = [tabBar.items objectAtIndex:2];

UIImage *inboxIconImage = [[UIImage imageNamed:@"inbox"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage *friendsIconImage = [[UIImage imageNamed:@"friends"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage *cameraIconImage = [[UIImage imageNamed:@"camera"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

tabInbox = [tabInbox initWithTitle:nil image:inboxIconImage selectedImage:inboxIconImage];
tabFriends = [tabFriends initWithTitle:nil image:friendsIconImage selectedImage:friendsIconImage];
tabCamera = [tabCamera initWithTitle:nil image:cameraIconImage selectedImage:cameraIconImage];
Ericson Ortega
Ericson Ortega
3,307 Points

solve it by adding a string to initWithTitle

Thanks