Configure iOS 5 TabBar

I am using the iOS 5 UI customization features to create a custom tabBar. I know how to place a custom background and selection element like this:

-(void)customizeAppearance { UIImage *tabBg = [UIImage imageNamed:@"myTabBar.png"]; [[UITabBar appearance] setBackgroundImage:navBg]; [[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"mySelector.png"]]; } 

I would also like to set the “selected” and “unselected” images for the tabBar icons. From the documentation, I see that you are using

 setFinishedSelectedImage: withFinishedUnselectedImage: 

to accomplish this. I have 4 tabs and they created 8 icons for them. The question is how to assign each selected / unselected image to each tab?

+8
iphone xcode ios5
source share
1 answer

You can call a method for each UITabBarItem in the tabBar property. For example:

 UIImage *selectedImage = [UIImage imageNamed:@"selected.png"]; UIImage *unselectedImage = [UIImage imageNamed:@"unselected.png"]; UITabBar *tabBar = tabBarViewController.tabBar; UITabBarItem *item1 = [tabBar.items objectAtIndex:0]; [item1 setFinishedSelectedImage:selectedImage withFinishedUnselectedImage:unselectedImage]; 

and the same for the other three elements. Hope this helps!

+20
source share

All Articles