UITabBar appearance setSelectionIndicatorImage does not work on first launch iOS7

后端 未结 5 2277
你的背包
你的背包 2021-02-13 05:51

I have a customised UITabBar and use the following code in the AppDelegate:

- (void)tabBarController:(MainUITabBarController *)tabBarController didSelectViewCont         


        
5条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-13 06:30

    ok.

    not the best of fixes but hey have to submit.

    Remove the customisation code in the appdelegate and in the projects xib file (is an old project) on the TabBars attributes inspector (using xcode 5) - add the tab bars background and selection images.

    This works for ios7 without the need for any of the customisation code in the appdelegate.

    For pre iOS5 + 6 (this app only supports 5+) however we still need the code so I added a simple check for version and kept the code as is:

    #define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
    
    if(SYSTEM_VERSION_LESS_THAN(@"7.0"))
    
        {
    
            UIImage *tabBackground = [[UIImage imageNamed:@"unselectedtab"]
    
                                      resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
    
            // Set background for all UITabBars
    
            [[UITabBar appearance] setBackgroundImage:tabBackground];
        [[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
    
        // Set tint colour for the images for all tabbars
    
        [[UITabBar appearance] setSelectedImageTintColor:[UIColor whiteColor]];
    
        // Set selectionIndicatorImage for all tabbars
    
        [[UITabBar appearance] setSelectionIndicatorImage:nil];
    
        [[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"selectedtab.png"]];
    
    }
    

提交回复
热议问题