1

I'd like to be able to change the highlighted state image on an UITabBarItem when it is selected? Is it possible to subclass and access this? or do I need to roll my own navigation code?

-> start edit I didn't articulate what I was looking for earlier. I am looking for the semi-transparent white overlay reference that the device adds to the selected state/image of the UITabBar. See image! http://solomon71.com/images/UITabBarItem.png

Paul Solomon
  • 91
  • 2
  • 4

2 Answers2

2

There is no documented or supported way to set your own highlighted image. Having said that, in 2.2 you could do it by subclassing UITabBarItem and implementing -[UIImage *)selectedImage.

Strictly speaking you are not calling private API, since selectedImage is not a reserved method name (and is actually a fairly reasonable name for someone to use themselves). Having said that, I am sure this is not intended and it could break at any time in a future release. It wouldn't shock me if this was already broken in 3.x (I never shipped anything that did this, just experimented with it for a client).

Louis Gerbarg
  • 43,356
  • 8
  • 80
  • 90
1

try this one.

I have change the selected tabbatitem image like -

in 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"]];
Muhammad Rizwan
  • 3,470
  • 1
  • 27
  • 35