tab bar icon selected image

梦想的初衷 提交于 2019-12-06 12:05:26

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!