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 trialTareq Alothman
17,921 PointsWhen 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
42,016 Pointsyou 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
17,921 PointsThank 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
42,016 Pointswoops sorry. I copied and pasted from an app I made previously and forgot to change those variable names there. its fixed now
Benjamin McMahan
6,679 PointsTHANK YOU!! This worked great. Was struggling trying to get fix everything. Really need a Teacher's Note for this with correct code.
Ericson Ortega
3,307 PointsHi 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
3,307 Pointssolve it by adding a string to initWithTitle
Thanks