问题与ios 7 tabbarcontroller

时间:2013-10-09 10:57:59

标签: objective-c uitabbarcontroller ios7 uitabbar

嗨我正在将我的应用程序从ios 6.1迁移到7,该应用程序包含一个tabbar控制器,在ios6上工作得非常好,但是当我在ios 7上运行时,5个tabbar项目中的4个不显示所选图像,非常奇怪,因为一个正确显示,而其他人没有,我正在使用故事板,我无法使用“imageWithRenderingMode:”,因为我仍然在xcode 4.6上这样做,所以我想在xcode 4.6中纠正它并且是能够在ios7上运行它,tabbarcontroller的代码给出,请原谅错误,如果有的话..

- (void)customizeTabbarBackgroundImages:(UITabBarController *)tabbarController
{
    //background of tabbar
    [tabbarController.tabBar setBackgroundImage:[UIImage imageNamed:@"tabbarBackground.png"]];

    //background for selected item
    [[tabbarController tabBar] setSelectionIndicatorImage:[UIImage imageNamed:@"tabbar-selection-background.png"]];

    //keep the item at index 2 as selected item
    tabbarController.selectedIndex = 2;
}


- (void)customizeTabbarItemImages:(UITabBarController *)tabbarController
{
    {
        //Index - Favourites
        [[tabbarController.tabBar.items objectAtIndex:0] setFinishedSelectedImage:[UIImage imageNamed:@"tabbar-favourites-icon-down.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"tabbar-favourites-icon.png"]];

        //Index - Search
        [[tabbarController.tabBar.items objectAtIndex:1] setFinishedSelectedImage:[UIImage imageNamed:@"tabbar-search-icon-down.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"tabbar-search-icon.png"]];

        //Index - Icon
        [[tabbarController.tabBar.items objectAtIndex:2] setFinishedSelectedImage:[UIImage imageNamed:@"tabbar-random-button"]withFinishedUnselectedImage:[UIImage imageNamed:@"tabbar-random-button"]];

        //Index - Profile
        [[tabbarController.tabBar.items objectAtIndex:3] setFinishedSelectedImage:[UIImage imageNamed:@"tabbar-profile-icon-down.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"tabbar-profile-icon.png"]];

        //Index - Settings
        [[tabbarController.tabBar.items objectAtIndex:4] setFinishedSelectedImage:[UIImage imageNamed:@"tabbar-settings-icon-down.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"tabbar-settings-icon.png"]];
    }
}

enter image description here

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:1)

你想要使用imageWithRenderingMode,你是在正确的轨道上。只需做这样的事情来调整UIImage以兼容两个ios版本:

UIImage *tabImage = [UIImage imageNamed:@"tabBar.png"];

if ([UIImage instancesRespondToSelector:@selector(imageWithRenderingMode:)]) {
    tabImage = [segmentImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}