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

前端 未结 11 925
陌清茗
陌清茗 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:11

    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];
    

提交回复
热议问题