1

我最近将 Xcode 更新到 5.1,现在标签栏出现问题。在 iOS 7 和 Xcode 5.0 中,我使用了以下代码:

// Graph tab icon
    UITabBar *tabBar = tabBarController.tabBar;
    UITabBarItem *graphTabIcon = [tabBar.items objectAtIndex:0];
    UIImage *noRenderGraph = [[UIImage imageNamed:@"graph"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [graphTabIcon setImage:noRenderGraph];
    [graphTabIcon setTitle:@"Graph"];
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor whiteColor], NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];
    // Friends tab icon
    UITabBarItem *friendsTabIcon = [tabBar.items objectAtIndex:1];
    UIImage *noRenderFriends = [[UIImage imageNamed:@"group"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [friendsTabIcon setImage:noRenderFriends];
    [friendsTabIcon setTitle:@"Friends"];
    // Settings tab icon
    UITabBarItem *settingsTabIcon = [tabBar.items objectAtIndex:2];
    UIImage *noRenderSettings = [[UIImage imageNamed:@"settings"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [settingsTabIcon setImage:noRenderSettings];
    [settingsTabIcon setTitle:@"Settings"];
    // Info tab icon
    UITabBarItem *infoTabIcon = [tabBar.items objectAtIndex:3];
    UIImage *noRenderinfo = [[UIImage imageNamed:@"info"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [infoTabIcon setImage:noRenderinfo];
    [infoTabIcon setTitle:@"Info"];

结果是这样的:

在此处输入图像描述

但现在有了 7.1 和 Xcode 5.1,我得到了这个: 在此处输入图像描述

我也试过这段代码:

[[UITabBar appearance] setSelectedImageTintColor:[UIColor whiteColor]];

这在 iOS 7.1 上看起来很棒,但在 7 上最终变成了浅棕色。

那么我怎样才能使它适用于两者呢?

4

1 回答 1

1

根据 Leo Natan 的评论,我这样做了:

编辑

我最终只是将两个代码片段添加在一起,它按我想要的方式工作

应用委托

{
    // iOS 7 method
    // Graph tab icon
    UITabBar *tabBar = tabBarController.tabBar;
    UITabBarItem *graphTabIcon = [tabBar.items objectAtIndex:0];
    UIImage *noRenderGraph = [[UIImage imageNamed:@"graph"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [graphTabIcon setImage:noRenderGraph];
    [graphTabIcon setTitle:@"Graph"];
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor whiteColor], NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];
    // Friends tab icon
    UITabBarItem *friendsTabIcon = [tabBar.items objectAtIndex:1];
    UIImage *noRenderFriends = [[UIImage imageNamed:@"group"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [friendsTabIcon setImage:noRenderFriends];
    [friendsTabIcon setTitle:@"Friends"];
    // Settings tab icon
    UITabBarItem *settingsTabIcon = [tabBar.items objectAtIndex:2];
    UIImage *noRenderSettings = [[UIImage imageNamed:@"settings"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [settingsTabIcon setImage:noRenderSettings];
    [settingsTabIcon setTitle:@"Settings"];
    // Info tab icon
    UITabBarItem *infoTabIcon = [tabBar.items objectAtIndex:3];
    UIImage *noRenderinfo = [[UIImage imageNamed:@"info"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [infoTabIcon setImage:noRenderinfo];
    [infoTabIcon setTitle:@"Info"];

    // iOS 7.1 method
    [[UITabBar appearance] setSelectedImageTintColor:[UIColor whiteColor]];
}
于 2014-04-16T20:24:30.363 回答