开发者

iPhone:Color of TabBar image?

开发者 https://www.devze.com 2023-02-18 15:41 出处:网络
I have added an image(Orange color) to TabBar, but when I run application image开发者_运维技巧 shown gray !

I have added an image(Orange color) to TabBar, but when I run application image开发者_运维技巧 shown gray ! How can I slove this problem ? thanks


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号