Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS5 TabBar Fonts and Color

I have customized the TabBar appearance such

UIImage *tabBackground = [[UIImage imageNamed:@"tab-bar-bg.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UITabBar appearance] setBackgroundImage:tabBackground];
[[UITabBar appearance] setSelectionIndicatorImage: [UIImage imageNamed:@"activetab.png"]];

How do I define the custom fonts and the selected and unselected text colors?

Thanks,

like image 643
slow_mondays Avatar asked Apr 23 '12 16:04

slow_mondays


3 Answers

[[UITabBarItem appearance] setTitleTextAttributes:
     [NSDictionary dictionaryWithObjectsAndKeys:
      [UIColor blackColor], UITextAttributeTextColor, 
      [UIFont fontWithName:@"font" size:0.0], UITextAttributeFont, 
      nil] 
                                             forState:UIControlStateHighlighted];
like image 86
user1351829 Avatar answered Nov 14 '22 11:11

user1351829


[[UITabBarItem appearance] setTitleTextAttributes:
     [NSDictionary dictionaryWithObjectsAndKeys:
      [UIColor blackColor], UITextAttributeTextColor, 
      [UIFont fontWithName:@"ProximaNova-Semibold" size:0.0], UITextAttributeFont, 
      nil] 
                                             forState:UIControlStateHighlighted];


    [[UITabBarItem appearance] setTitleTextAttributes:
     [NSDictionary dictionaryWithObjectsAndKeys:
      [UIColor grayColor], UITextAttributeTextColor, 
      [UIFont fontWithName:@"ProximaNova-Semibold" size:0.0], UITextAttributeFont, 
      nil] 
                                             forState:UIControlStateNormal];
like image 40
slow_mondays Avatar answered Nov 14 '22 11:11

slow_mondays


The above answer is working for me.

But I think most people should change the forState:UIControlStateHighlighted to forstate:UIControlStateSelected

like image 1
XcodeNOOB Avatar answered Nov 14 '22 12:11

XcodeNOOB