Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change UITabBar Selection color

I need to change the selection color of UITabBar from default blue to red. How do we do this.

like image 280
saikamesh Avatar asked Apr 26 '09 12:04

saikamesh


People also ask

How do I create a custom tab bar in Swift?

Implement a view controller that can hold some other view controllers. Show one of those view controllers. Show a tab bar at the bottom of the screen over the shown view controller. Switch between the various view controllers when the user taps on a tab bar button.


2 Answers

In IOS5, UITabBar has a selectedImageTintColor property which does what you need.

like image 41
Daniele Grassi Avatar answered Sep 21 '22 15:09

Daniele Grassi


Update September 2017: It's been two years since I've written this answer and since it's receiving upvotes regularly, I should say this is probably the worst possible answer to this question, it's error prone, likely to break because of iOS updates, hard to debug, etc., so please don't do the things I've written and apply better solutions such as subclassing UITabBar or UITabBarController. Thanks.

You can do this by setting a "tintColor" attribute (Key Path) for you UITabBar.

  1. Select the UITabBar in the document outline. (NOT the Controller with the yellow icon.)
  2. Select Identity Inspector in the Utilities area.
  3. Click the + in "User Defined Runtime Attributes."
  4. Add a "tintColor" Key Path of type "Color" and the color you want.

This should do it. You can check it against the screenshot below.

enter image description here

More on this: There's a "Tint" attribute in Identity Inspector of UITabBar which I believed would do the exact same thing but apparently, it does nothing. It's default value is the exact default fill color when a UITabBarItem is selected, so my guess is it would be fixed in the stable release Xcode 7. Fingers crossed.

like image 55
Behdad Avatar answered Sep 18 '22 15:09

Behdad