Custom tab bar icon colors

后端 未结 7 1137
傲寒
傲寒 2020-12-08 12:39

Im currently using Xcode 5 to develop a list oriented app. I have a custom tint for the tab bar, custom images for the tab icons, custom tint for the tab bar\'s icon images

7条回答
  •  囚心锁ツ
    2020-12-08 13:00

    You need to set the rendering mode for each tab's (unselected) image to UIImageRenderingModeAlwaysOriginal. So, in your app delegate, get a reference to the tab bar and then iterate over each tab bar item, adjusting the image modes.

    There's probably a better way to get a reference to the tab bar, but I did the following:

    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UITabBarController *tbc = [sb instantiateInitialViewController];
    self.window.rootViewController = tbc;
    UITabBar *tb = tbc.tabBar;
    

    Then the image adjustment can be done as follows:

    NSArray *items = tb.items;
    
    for (UITabBarItem *tbi in items) {
        UIImage *image = tbi.image;
        tbi.selectedImage = image;
        tbi.image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    }
    

提交回复
热议问题