tab bar icon selected image

2019-04-13 03:28发布

How to customize the selected image/icon on the tab bar? Is this possible?

Pls advise. Thanks

4条回答
神经病院院长
2楼-- · 2019-04-13 03:34

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.

查看更多
再贱就再见
3楼-- · 2019-04-13 03:39

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"]];
查看更多
Lonely孤独者°
4楼-- · 2019-04-13 03:47

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.. :)

查看更多
姐就是有狂的资本
5楼-- · 2019-04-13 03:58

Yes. Just read the Apple documentation

You can do by IB or code

查看更多
登录 后发表回答