iOS 7中的UITabBar色调

如何select和取消选中选项卡时指定图像的色调?

我试过这个,但它不工作:

[[UITabBar appearance] setTintColor:[UIColor redColor]]; [[UITabBar appearance] setSelectedImageTintColor:[UIColor greenColor]]; 

这使得选定的图像色调为红色(而不是绿色)和未选定的色调灰色(而不是红色)。

您可以为选定的和未选中的选项卡栏button设置色调颜色,如下所示:

 [[UIView appearanceWhenContainedIn:[UITabBar class], nil] setTintColor:[UIColor redColor]]; [[UITabBar appearance] setSelectedImageTintColor:[UIColor greenColor]]; 

第一行设置未选中的颜色 – 在本例中为红色 – 通过设置UIView的tintColor,当它包含在标签栏中时。 请注意,这只会设置未select的图像的色调颜色 – 它不会更改它下面的文本的颜色。

第二行将选项卡栏的选定图像色调颜色设置为绿色。

您是否使用图像的模板版本?

而不是使用[UIImage imageNamed: @"MyImage"]设置图像,使用[[UIImage imageNamed: @"MyImage"] imageWithRenderingMode: UIImageRenderingModeAlwaysTemplate]设置它们。

这个设置以及你的代码应该可以解决这个问题。

你必须使用在iOS 7中引入的新的图像呈现模式( UIImageRenderingModeAlwaysOriginalUIImageRenderingModeAlwaysTemplate )看到我的答案类似的问题 :

希望这可以帮助

如果你没有许多viewcontrollers。 这是我的方式来做到这一点。

在你的委托方法只是把你的tabbar bg图像。 并设置UIImageView

在AppDelegate.h中创buildUITabbar实例

 @property (nonatomic,retain) UITabBar *tabbar; 

 @synthesize tabbar; UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController; tabbar = [tabBarController tabBar]; [tabbar setBackgroundImage:[UIImage imageNamed:@"tabbarBg.png"]]; NSArray *tabImageArray = [NSArray arrayWithObjects: [UIImage imageNamed:@"tab1Hover.png"], [UIImage imageNamed:@"tab2.png"], [UIImage imageNamed:@"tab3.png"], [UIImage imageNamed:@"tab4.png"], [UIImage imageNamed:@"tab5.png"], nil]; for (int i = 0; i<5; i++) { UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(20+i*60+i*3.5, 10, 25, 21)]; [image setContentMode:UIViewContentModeScaleAspectFit]; [image setImage:[tabImageArray objectAtIndex:i]]; [image setTag:10+i]; [tabbar addSubview:image]; } 

然后在tabbar中添加每个ViewController

 -(void)viewWillAppear:(BOOL)animated 

委托方法和这个方法。 您可以更改Imageviews,如下所示。

 -(void)viewWillAppear:(BOOL)animated{ AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; UITabBarController *tabBarController = (UITabBarController *)appDelegate.window.rootViewController; NSArray *tabImageArray = [NSArray arrayWithObjects: [UIImage imageNamed:@"tab1Hover.png"], [UIImage imageNamed:@"tab2.png"], [UIImage imageNamed:@"tab3.png"], [UIImage imageNamed:@"tab4.png"], [UIImage imageNamed:@"tab5.png"], nil]; for (int i = 0; i<5; i++) { UIImageView *image = (UIImageView*)[tabbar viewWithTag:10+i]; [image setImage:[tabImageArray objectAtIndex:i]]; } } 

所以,只需要在每个View控制器中使用tabImageArray。 那么你可以使用它。

我也在iOS 7上工作。