iPhone:Color of TabBar image?

ⅰ亾dé卋堺 提交于 2019-12-05 07:46:44

问题


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


回答1:


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.




回答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.



来源:https://stackoverflow.com/questions/5361851/iphonecolor-of-tabbar-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!