Change tintColor of unselected UITabBarController item title and background image

前端 未结 4 1911
心在旅途
心在旅途 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:44

    Figured it out!

    Use this to change the color of the text:

    [[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor greenColor] }
                                             forState:UIControlStateNormal];
    [[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor blackColor] }
                                             forState:UIControlStateSelected];
    

    And make sure that image rendering mode is set to ORIGINAL for the images

    UIImage *deselectedImage = [[UIImage imageNamed:@"deselectedImage"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage *selectedImage = [[UIImage imageNamed:@"selectedImage"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    

提交回复
热议问题