Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the tabbar selected image using storyboard

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?

like image 922
AMohan Avatar asked May 07 '13 10:05

AMohan


People also ask

How do I add an image to the tab bar in IOS?

iOS UITabBarController Changing Tab Bar Item Title and Icon For a custom icon, add the required images to the assets folder and set the 'System Item' from earlier to 'custom'. Now, set the icon to be shown when the tab is selected from the 'selected image' drop down and the default tab icon from the 'image' drop down.


1 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.

like image 141
Andrew Avatar answered Oct 20 '22 19:10

Andrew