Change tintColor of unselected UITabBarController item title and background image

前端 未结 4 1910
心在旅途
心在旅途 2020-12-28 17:12

How can I change the tintColor of an unselected UITabBarItem title and background image iOS 8?

The default color for an unselected state is a light gray color, but

4条回答
  •  不知归路
    2020-12-28 17:21

    In your AppDelegate.m inside of application didFinishLaunchingWithOptions: use the following code:

    //unselected icon tint color 
    [[UIView appearanceWhenContainedIn:[UITabBar class], nil] setTintColor:[UIColor redColor]];
    
    //selected tint color 
    [[UITabBar appearance] setTintColor:[UIColor greenColor]];
    
    //text tint color 
    [[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor whiteColor] }
                                         forState:UIControlStateNormal];
    
    //background tint color 
    [[UITabBar appearance] setBarTintColor:[UIColor blueColor]];
    

提交回复
热议问题