2

I would like to change the font of a selected UITabBarItem to bold if it is selected. I have done following to set image and text to white and I also set the font, but only the color changes on selecting UITabBarItem, not the font.

// Normal font       
[self.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:MY_LIGHT_FONT, NSFontAttributeName, [UIColor grayColor], NSForegroundColorAttributeName,nil] forState:UIControlStateNormal];

// Selected font
[self.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:MY_BOLD_FONT, NSFontAttributeName, [UIColor whiteColor], NSForegroundColorAttributeName,nil] forState:UIControlStateSelected];

The selected font does not change anything.

enter image description here

The calendar text should be bold.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Michi-2142
  • 1,170
  • 3
  • 18
  • 39

4 Answers4

2

As @TimurBernikowich mentioned, font parameter doesn't work for selected state on iOS11.

Michi-2142
  • 1,170
  • 3
  • 18
  • 39
1
  [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:MONSREGULAR size:10.0f],
                                                        NSForegroundColorAttributeName :[UIColor colorWithRed:0.004 green:0.820 blue:0.369 alpha:1.00];
                                                        } forState:UIControlStateSelected];


    [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:MONSREGULAR size:10.0f],
                                                        NSForegroundColorAttributeName :[UIColor darkgraycolor];
                                                        } forState:UIControlStateNormal];
Arun
  • 624
  • 4
  • 18
0

Try this:

// Normal font       
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:MY_LIGHT_FONT, NSFontAttributeName, [UIColor grayColor], NSForegroundColorAttributeName,nil] forState:UIControlStateNormal];

// Selected font
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:MY_BOLD_FONT, NSFontAttributeName, [UIColor whiteColor], NSForegroundColorAttributeName,nil] forState:UIControlStateSelected];
Sargis
  • 1,196
  • 1
  • 18
  • 31
0

tried this:

    // Normal font
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"your-font" size:10.f],  NSFontAttributeName, nil] forState:UIControlStateNormal];

   //selected state
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"your-font bold" size:10.f], NSFontAttributeName, nil] forState:UIControlStateSelected];
NAVEEN KUMAR
  • 669
  • 6
  • 25