How to change the tabbar selected image using storyboard

12,656

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.

enter image description here

Share:
12,656

Related videos on Youtube

AMohan
Author by

AMohan

I am an iOS developer.

Updated on September 15, 2022

Comments

  • AMohan
    AMohan over 1 year

    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?

  • AMohan
    AMohan almost 11 years
    I have 5 tabs where should I write this code. In each viewController.?