How to change UITabBar Selection color

2019-01-22 01:56发布

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

12条回答
手持菜刀,她持情操
2楼-- · 2019-01-22 02:31

Because UITextAttributeTextColor is deprecated in iOS 7, you should use:

[UITabBarItem.appearance setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor greenColor]} forState:UIControlStateNormal];    
[UITabBarItem.appearance setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor purpleColor]} forState:UIControlStateSelected];
查看更多
叼着烟拽天下
3楼-- · 2019-01-22 02:34

It is extremely easy

Create a custom class of UITabBarController and in -(void)viewDidLoad method add this line:

[[self tabBar] setSelectedImageTintColor:[UIColor greenColor]]; 
查看更多
姐就是有狂的资本
4楼-- · 2019-01-22 02:34

Simply change the following property in Interface Builder for the TabBar

Obviously in my case its White.

查看更多
贼婆χ
5楼-- · 2019-01-22 02:34

iOS 5.0 fixes this issue but the solution is under NDA. Look up UITabBar in your documentation for an EASY way to do what you want to do.

查看更多
地球回转人心会变
6楼-- · 2019-01-22 02:39

In iOS 7 it's simply the tintColor. One way to accomplish this could be to subclass UITabBarViewController, set the custom class in the storyboard, and in your viewDidLoad method of the subclassed tabBarVC add this:

[[self tabBar] setTintColor:[UIColor redColor]];
查看更多
Luminary・发光体
7楼-- · 2019-01-22 02:41

I found the easiest solution -

  1. Select Tab Bar in Tab Bar Controller

  2. Set Image Tint color

  3. Set Tint Color

For reference see the attached image.

enter image description here

查看更多
登录 后发表回答