To change the color of unselected UITabBar icon in iOS 7?

后端 未结 4 1168
小蘑菇
小蘑菇 2020-12-08 22:09

I know this question has been asked earlier as well, but still i didn\'t get any solution searching the solution on internet.

I referred the following posts:

4条回答
  •  遥遥无期
    2020-12-08 22:45

    I'm assuming that you do not want to change the color using tintColor? Another option is to use two images that look exactly the same, but differ in color. One image is the selected tab, the other is unselected.

    In your AppDelegate.m - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions function, try this.

    UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
    UITabBar *tabBar = tabBarController.tabBar;
    
    // repeat for every tab, but increment the index each time
    UITabBarItem *firstTab = [tabBar.items objectAtIndex:0];
    
    // also repeat for every tab
    firstTab.image = [[UIImage imageNamed:@"someImage.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
    firstTab.selectedImage = [[UIImage imageNamed:@"someImageSelected.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    

    Edit: For those who don't have the tab bar controller as their root view controller, you can grab the controller like this and the rest of the code is the same.

    UITabBarController *tabBarController = self.tabBarController;

提交回复
热议问题