How to change the tabbar selected image using storyboard
Solution 1
- (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.
Solution 2
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.
Solution 3
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.
Related videos on Youtube
Comments
-
AMohan over 1 year
I have created application using storyboard and has
TabBarController
with 5 tabs. Each tab has tabicon andtab title
. When a tab is selected I want to change thetabbar
icon. How can I do usingstoryboard
? -
AMohan almost 11 yearsI have 5 tabs where should I write this code. In each viewController.?