Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOS 5 TabBar customization

Tags:

xcode

iphone

ios5

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 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?

like image 698
awDemo Avatar asked Oct 14 '11 20:10

awDemo


1 Answers

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!

like image 114
cpprulez Avatar answered Oct 21 '22 09:10

cpprulez