问题
How to customize the selected image/icon on the tab bar? Is this possible?
Pls advise. Thanks
回答1:
Its possible without adding any subView.
In the class where you define the tab bar set the property of the tabBarItem to ->>
UITabBarItem *tabBarItem1 = [[self.tabBar.tabBar items] objectAtIndex:0];
[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"campaigns_hover.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"campaigns.png"]];
Its a property of tabBarItem and u can change the default blue image to a custom image. campaigns_hover.png is the selected custom image AND campaigns.png is the custom image when not selected...
Enjoy the secret.. :)
回答2:
In iOS 6 I have change the selected Tabbaritem image like -
In the Tabbar controller delegate method
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
if([tabBarController selectedIndex] == 0)
{
[viewController.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"selected.png"]withFinishedUnselectedImage:[UIImage imageNamed:@"unselect.png"]];
}
}
through this you can change your image.
Or you can use directly in your view controllers init(or ViewWillAppear) method, like
[viewController.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"selected.png"]withFinishedUnselectedImage:[UIImage imageNamed:@"unselect.png"]];
回答3:
You can change the image, but the selected image always has the same blue overlay applied to the image. The only way I can see getting around this might be to subclass UITabBarItem.
回答4:
Yes. Just read the Apple documentation
You can do by IB or code
来源:https://stackoverflow.com/questions/4030741/tab-bar-icon-selected-image