2015-04-16 28 views
1

我是iOS新手,我被困在设计中。我已经搜索了几个帖子,但没有一个帮助。在不影响色调的情况下更改标签栏项目背景颜色

大多数帖子都建议用图片替换整个标签栏项目,我认为这不是一个好主意。

我期望故事板中的配置(如:用户定义的运行时属性)可以帮助更改项目的背景色,而不会影响其TINT COLOR。

这是我试图实现的结果。

enter image description here

+0

PLZ不要工作在您的标题 – progsource

+1

中注意不到尖叫,对此感到抱歉:( –

回答

1

您可以设置背景图片的TabBar像这样,倒不如通过这种方式来定制的TabBar控制器。

在头文件

#import <UIKit/UIKit.h> 

@interface CustomTabBarController : UITabBarController 

-(void) setBGView; 

@end 

在M档。

#import "CustomTabBarController.h" 

@implementation CustomTabBarController 
- (void)viewDidAppear:(BOOL)animated { 
    [super viewDidAppear:animated]; 
} 
-(void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    [self setBGView]; 
} 
-(void)setBGView 
{ 
    // Background 
    UIImageView* bgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"TabBG.png"]] ; //You can create single color image or Single Color view to add 
    bgView.frame = CGRectMake(0, self.view.frame.size.height-60, elf.view.frame.size.widdth, 60); 
    [self.view addSubview:bgView]; 

@end 

HTH,Enjoy Coding !!

+0

嗨病毒,我按照你的建议,并结束了像这样的图像:http://postimg.org/image/gbevrvjtx/,忽略我的不良切割技巧,整个标签栏充满了红色矩形现在,我试过insertSubview方法,仍然无法获得预期的输出 –

+0

“我尝试过insertSubview方法,仍然无法获得预期的输出”的意思? –

+0

起初,我怀疑矩形重叠的标签栏项目的图像和标题,所以我使用[self.view insertSubview:bgView atIndex:0];测试它,但红色矩形不可见。我已经在我的问题中发布了预期的输出,其中红色矩形只占用选定的标签栏项目,并且不与其中的其他组件重叠 –

1

由于从 here

我设法实现类似我的问题输出到@ViralSavaj和tagyro,看起来像“setSelectionIndicatorImage”是实现这样输出的唯一途径。

但是,当你在其他设备上运行的输出可能不是很好的,解决这个问题的一种方法是根据设备的分辨率来绘制形状,你可以从上面的链接获得的片段

提防代码的你@tagyro

CGSize tabSize = CGSizeMake(CGRectGetWidth(self.view.frame)/5, 49); 

你可能要根据你的标签的数量来改变/ 5重用,在我的情况,我只需要把4来完成

相关问题