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
?
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.
- (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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With