0

I have added an image(Orange color) to TabBar, but when I run application image shown gray ! How can I slove this problem ? thanks

Dilip Manek
  • 9,095
  • 5
  • 44
  • 56
mahdi
  • 16,257
  • 15
  • 52
  • 73

2 Answers2

3

The color is fixed to blue. You could either try to write your own custom tab bar interface, or hack together something to place custom icons over the tab bar in a subclassed UITabBarController, like this:

-(void)setActiveCustomOverlay
{
    if ( self.activeOverlay )
    {
            [self.activeOverlay removeFromSuperview];
    }

    NSString *imagename = [NSString stringWithFormat:@"tab_%d.png",
                                                        [self selectedIndex]];
    UIImage *img = [UIImage imageNamed:imagename];
    self.activeOverlay = [[[UIImageView alloc] initWithImage:img] autorelease];
    self.activeOverlay.frame = CGRectMake(2.0f+64.0f*[self selectedIndex],3.0f,60.0f,44.0f);

    [tabbar addSubview:activeOverlay];
    [tabbar bringSubviewToFront:activeOverlay];
}

And also do this:

  • add a UIView property (nonatomic, retain) called activeOverlay
  • add a tabbar property and hook it to the tab bar in IB
  • call setActiveCustomOverlay whenever the tab changes.

This is an ugly hack, but the easiest fix to implement in existing projects. Apple will not reject it either.

For iPad you need to tweak the numbers, and use wider tab bar images.

mvds
  • 45,755
  • 8
  • 102
  • 111
2

The tab bar image color cannot be changed, it should be always be in the default color. Do read the Human interface guidelines of ios for more details.

Swapna
  • 2,245
  • 2
  • 19
  • 22
  • 2
    True, but given how often Apple violate their own HIGs (like the Game Center app, which uses colored custom tab-bar icons) there's no reason why people shouldn't be able to do this in their own apps, albeit via rather hacky solutions. – lxt Mar 19 '11 at 13:15