本文介绍了iPhone:TabBar图像的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在TabBar中添加了一个图像(橙色),但是当我运行应用程序图像时显示为灰色!
我该如何解决这个问题?
谢谢

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

推荐答案

颜色固定为蓝色。您可以尝试编写自己的自定义标签栏界面,或者将一些内容放在一起,将自定义图标放在子类 UITabBarController 中的标签栏上,如下所示:

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];
}

并且这样做:


  • 添加 UIView 属性(非原子,保留),名为 activeOverlay

  • 添加标签栏属性并将其挂钩到IB中的标签栏

  • call <$ c每当标签发生变化时,$ c> setActiveCustomOverlay 。

  • 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.

这是一个丑陋的黑客攻击,但最简单的解决方法是在现有项目中实施。 Apple也不会拒绝它。

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

对于iPad,您需要调整数字,并使用更宽的标签栏图像。

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

这篇关于iPhone:TabBar图像的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 01:14