Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the text and icon colors for tabBarItems in iOS 7?

How can I change the text and icon colors for UITabBar and UITabBarItems in iOS 7? The default gray text seems dim and hard to read for unselected tabbar items.

like image 405
Ed Fernandez Avatar asked Sep 11 '13 07:09

Ed Fernandez


People also ask

How do I add an image to the tab bar in iOS?

iOS UITabBarController Changing Tab Bar Item Title and Icon For a custom icon, add the required images to the assets folder and set the 'System Item' from earlier to 'custom'. Now, set the icon to be shown when the tab is selected from the 'selected image' drop down and the default tab icon from the 'image' drop down.


1 Answers

There are two things you need to do for this:

1) If you want to customize the TabBar itself, you need to set the barTintColor for the tabBarController:

    // this will generate a black tab bar     tabBarController.tabBar.barTintColor = [UIColor blackColor];      // this will give selected icons and text your apps tint color     tabBarController.tabBar.tintColor = appTintColor;  // appTintColor is a UIColor * 

2) Set the tabBarItem text appearance for each state that you want to override:

[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:10.0f],                                                     NSForegroundColorAttributeName : appTintColor                                                     } forState:UIControlStateSelected];   // doing this results in an easier to read unselected state then the default iOS 7 one [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:10.0f],                                                     NSForegroundColorAttributeName : [UIColor colorWithRed:.5 green:.5 blue:.5 alpha:1]                                                     } forState:UIControlStateNormal]; 
like image 102
Ed Fernandez Avatar answered Oct 24 '22 03:10

Ed Fernandez