Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom tab bar icon colors

Tags:

xcode

ios

xcode5

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 when its selected, but i cannot find how to customize the icon images' tint for when its not selected. Right now its just the default gray which you can barely see in contrast to my green tab bar. I want to make the tab bar icons' images and names white.

Does anybody know how to set the tab bar icons' image tint in Xcode 5?

like image 550
ian Avatar asked Sep 24 '13 17:09

ian


People also ask

How do I change the TabView color in SwiftUI?

To change the background color and default tab item colors, some extra work is required as demonstrated below. As shown in lines 2-4, we can use UITabBar. appearance(). backgroundColor to modify the color of the tab bar.


4 Answers

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];
}
like image 64
Matthew Burke Avatar answered Sep 19 '22 05:09

Matthew Burke


You can try this to tint selected icon :

// Custom the tab bar
[[UITabBar appearance] setSelectedImageTintColor:[UIColor whiteColor]];

and this to tint the non active icon :

[self.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"item_seleted.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"item_unselected.png"]];
like image 24
Jordan Montel Avatar answered Sep 19 '22 05:09

Jordan Montel


You can do this purely from the storyboard without writing any code by adding a "User Defined Runtime Attribute":

  1. Select your UITabViewController in the storyboard
  2. Open the "Document Outline" and make sure that you select the "Tab Bar" view in the scene.
  3. Show the "Identity Inspector". You should see a section for "User Defined Runtime Attributes"
  4. Add the following:
    • Key Path: tintColor
    • Type: Color
    • Value: Select the color you want.
like image 27
tebs1200 Avatar answered Sep 20 '22 05:09

tebs1200


Try this way..it worked for me

In app delegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{


 UITabBarController *tabBarController=(UITabBarController*)(self.window.rootViewController);
    UITabBar *tabBar=tabBarController.tabBar;
  UITabBarItem *tabBarItem1=[[tabBar items] objectAtIndex:0];//first tab bar
 [tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"yourImageSelected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"yourImageUnselected.png"]];//image should be 30 by 30
}

run and go

like image 45
Tunvir Rahman Tusher Avatar answered Sep 20 '22 05:09

Tunvir Rahman Tusher