IOS 5 TabBar customization
I'm taking advantage of IOS 5's UI customization features to create a custom tabBar. I know how to place a custom background and selection item like so:
-(void)customizeAppearance {
UIImage *tabBg = [UIImage imageNamed:@"myTabBar.png"];
[[UITabBar appearance] setBackgroundImage:navBg];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"mySelector.png"]];
}
I'd also like to set the "selected" and "unselected" images for the tabBar icons. From the documentation, I see that you use the
setFinishedSelectedImage: withFinishedUnselectedImage:
method to accomplish开发者_如何学C this. I have 4 tabs and have created the necessary 8 icons for them. The question is how do I assign each selected/unselected image set to each tab?
You could call the 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 items. I hope this helps!
精彩评论