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

前端 未结 11 901
陌清茗
陌清茗 2020-12-02 07:26

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.

11条回答
  •  自闭症患者
    2020-12-02 08:12

    Tested in iOS 8 for permanent text color (selected/unselected) and image colors (selected/unselected) without create two images with different colors foreach tab:

    Text color:

    [[UITabBar appearance] setTintColor: selectedTabColor ];
        [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                           **yourFont**, NSFontAttributeName,
                                                           ** selectedTabColor**, NSForegroundColorAttributeName,
                                                           nil] forState:UIControlStateNormal];
    
        [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                           **yourFont**, NSFontAttributeName,
                                                           **selectedTabColor**, NSForegroundColorAttributeName,
                                                           nil] forState:UIControlStateSelected];
    

    Images color: (assuming that the original images have the color you want display as unselected)

    In a UITabBarController subclass -awakeFromNib :

        for (int i =0; i

    Credits: the whole internet and stack overflow XD

提交回复
热议问题