0

I have two custom tab bar items which i want to be highlighted in color when they are selected in a certain controller. However, when they are not selected, i want tabbar to show transparent tab bar item images which i have created.

I tried implementing the respective code in view controllers, but it's not working properly.

[[self tabBarItem] setFinishedSelectedImage:[UIImage imageNamed:@"tab.png"] `withFinishedUnselectedImage:[UIImage imageNamed:@"transparent.png"]];`

in - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil method

What am i doing wrong?

Monis Manzoor
  • 183
  • 3
  • 14

1 Answers1

0

Use the following to customize your tab bar:

//UITabBar Customizing Appearance
{
    [[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"tabBarBg"]];

    int numberOfTabs = 0;
    numberOfTabs = [[self.tabBarController viewControllers] count];

    UIImage *selectionIndicatorImage = [UIImage imageNamed:@"selectionIndicatorImage"];
    if (numberOfTabs) {
        selectionIndicatorImage = [AppDelegate scaleImage:selectionIndicatorImage
                                                   toSize:CGSizeMake((320.0/numberOfTabs), selectionIndicatorImage.size.height)];
    }

    [[UITabBar appearance] setSelectionIndicatorImage:selectionIndicatorImage];        
    [[UITabBar appearance] setSelectedImageTintColor:[UIColor colorWithRed:0.0 green:169.0/255.0 blue:157.0/255.0 alpha:1.0]];

    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                       [UIColor colorWithWhite:1.0 alpha:1], UITextAttributeTextColor,
                                                       [UIColor lightGrayColor], UITextAttributeTextShadowColor, nil]
                                             forState:UIControlStateNormal];
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                       [UIColor colorWithWhite:1.0 alpha:1], UITextAttributeTextColor,
                                                       [UIColor lightGrayColor], UITextAttributeTextShadowColor, nil]
                                             forState:UIControlStateSelected];
}

Use created images as the image for the selected and unselected tab items.Also you can specify the number of tabs.

Tinu C Joseph
  • 98
  • 1
  • 6