I have created application using storyboard and has TabBarController
with 5 tabs.
Each tab has tabicon and tab title
. When a tab is selected I want to change the tabbar
icon.
How can I do using storyboard
?
-
In Xcode 6 you would think you can do this with the new "Selected Image" field in the Attributes Inspector for the Tab Bar item, but for some reason that results in a blank image when selected, as of Xcode 6.1.1 anyway. However, there is a workaround detailed here: http://stackoverflow.com/a/26802597/650558 – Mason G. Zhwiti Jan 07 '15 at 05:26
4 Answers
- (void)setFinishedSelectedImage:withFinishedUnselectedImage:
is deprecated. If you're using storyboards, it's as simple as
UITabBarItem *tabBarItem0 = [self.tabBar.items objectAtIndex:0];
UIImage* selectedImage = [[UIImage imageNamed:@"settings-active"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tabBarItem0.selectedImage = selectedImage;
EDIT
In Swift:
var settingsItem = self.tabBar.items?[0] as UITabBarItem
settingsItem.selectedImage = UIImage(named: "home-selected")
Note that this code belongs in the viewDidLoad
override of your UITabBarController
subclass.

- 4,145
- 2
- 37
- 42
I have got it.
Subclass UITabBarController
- MyTabBarController
Over write viewDid load :
write
UITabBarItem *tabBarItem0 = [self.tabBar.items objectAtIndex:0];
[tabBarItem0 setFinishedSelectedImage:[UIImage imageNamed:@"selectedimage.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"image.png"]];
like this set for all the tabbar items and in story board set the tabBar controller to MyTabBarController
. It's working fine.

- 534
- 1
- 6
- 15
You can now do this easily in storyboard. On each tabviewcontroller that you have, it should contain a Tab Bar Item in the hierarchy (looks like a little blue star), Click on this and the settings on the right should look like the image below. The tab bar title & image can be changed here.

- 1,246
- 11
- 12
Below code will change tabbar image in selection:
UITabBarItem *tabBarItem = [[tabbar items] objectAtIndex:0];
[tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"img_hover.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"img.png"]];
change identifier to custom and add image

- 492
- 3
- 11