UITabBar not showing selected item images in ios 7

后端 未结 20 1845
我在风中等你
我在风中等你 2020-11-29 18:36

The icons show fine in ios 6 but not in ios 7. I\'m setting the selected state in the viewController viewDidLoad method. When the user selects a tab bar item the image disap

20条回答
  •  庸人自扰
    2020-11-29 18:51

    if you are working with storyboards you have to put the identifier : "custom" in Navigation Controller.

    then :

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        // Assign tab bar item with titles
        UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
        UITabBar *tabBar = tabBarController.tabBar;
        UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
        UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1];
        UITabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:2];
    
        (void)[tabBarItem1 initWithTitle:nil image:[UIImage imageNamed:@"home.png"] selectedImage:[UIImage imageNamed:@"home_selected.png"]];
        (void)[tabBarItem2 initWithTitle:nil image:[UIImage imageNamed:@"home.png"] selectedImage:[UIImage imageNamed:@"home_selected.png"]];
        (void)[tabBarItem3 initWithTitle:nil image:[UIImage imageNamed:@"home.png"] selectedImage:[UIImage imageNamed:@"home_selected.png"]];
    
        // Change the tab bar background
        UIImage* tabBarBackground = [UIImage imageNamed:@"tabbar.png"];
        [[UITabBar appearance] setBackgroundImage:tabBarBackground];
    
    
    
        return YES;
    }
    

    This works for me.

提交回复
热议问题