Search code examples
iosxcodeuitabbaruibarbuttonitem

UIBarbutton Item - image selected and un, not shown when called programmatically


It works in selected state, hence when you select either one of the tabs, but when app launched the images are not visible. (I think there seems to be a problem with the unselected state and not the selected state, because that's the one not shown or called). Anyways' here is a screenshot for demonstrationenter image description here purposes.

Here's the code use

header file. a simple IBOutlet uibarbutton item *Namedsomething;
[TabBarGroceryAdsIcon setFinishedSelectedImage:[UIImage imageNamed:@"Namedsomethingselected.png"]   withFinishedUnselectedImage:[UIImage imageNamed:@"NamedsomethingUnselected.png"]];

I'm developing for ios 6 and using storyboard. Any help would be appreciated very much :) CHeers, Daniel Ran


Solution

  • Programmaticaly, you can set our tabbarbuttons with an array.

    First, set your buttons with :

    UITabBarItem *myButton1 = [[UITabBarItem alloc] initWithTitle:@"Title" image:[UIImage imageNamed:@"image.png"] tag:i]
    

    Then, init a NSArray with this buttons :

    NSArray *myArray = [[NSArray alloc] initWithObjects:myButton1,myButton2,..., nil]
    

    Finally, set your tabBar items :

    [myTabBar setItems:myArray];