How can I change the text and icon colors for tabB

2019-01-10 05:38发布

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.

10条回答
Bombasti
2楼-- · 2019-01-10 06:18

You try it

for (UITabBarItem *item in self.tabBarController.tabBar.items) {
        item.image = [[UIImage imageNamed:@"youimage.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

        [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                           [UIColor whiteColor], UITextAttributeTextColor,
                                                           nil] forState:UIControlStateNormal];

        item.selectedImage = [UIImage imageNamed:@"youimage.png"];
    }
查看更多
叛逆
3楼-- · 2019-01-10 06:20

Code free way to change text color in tab bar:

If you are just using iOS 10 then you may change the Image Tint in your Tab Bar

enter image description here

If you are also supporting iOS 9 and lower, then you must also add tintColor to your user definer runtime attributes in each tab bar item

enter image description here

if you also wish to change your icon color make sure the correct color image is in your assest folder and change Render as to Original Image

enter image description here

查看更多
Explosion°爆炸
4楼-- · 2019-01-10 06:20

This Should Work Perfectly for iOS 8 also

For unselected tabbar item:

[[UIView appearanceWhenContainedIn:[UITabBar class], nil] setTintColor: [UIColor whiteColor]];

For selected tabbar item:

[[UITabBar appearance] setTintColor:[UIColor orangeColor]];
查看更多
别忘想泡老子
5楼-- · 2019-01-10 06:28

Ed's answer is perfect, but let me add one thing. TabBar is in default translucent thus affected by the color of view under the TabBar (i.e. each member viewController's view's color affects TabBar appearance.).

So I set below code not to be affected.

self.tabBarController.tabBar.translucent = false;

Together with Ed's answer here is a complete code I use now.

self.tabBarController.tabBar.barTintColor = [UIColor blackColor];
self.tabBarController.tabBar.translucent = false;
self.tabBarController.tabBar.tintColor = [UIColor blueColor];
查看更多
登录 后发表回答