13

我已经自定义了 TabBar 的外观,例如

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

如何定义自定义字体以及选定和未选定的文本颜色?

谢谢,

4

3 回答 3

19
[[UITabBarItem appearance] setTitleTextAttributes:
     [NSDictionary dictionaryWithObjectsAndKeys:
      [UIColor blackColor], UITextAttributeTextColor, 
      [UIFont fontWithName:@"font" size:0.0], UITextAttributeFont, 
      nil] 
                                             forState:UIControlStateHighlighted];
于 2012-04-23T18:25:09.553 回答
13
[[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];
于 2012-04-23T18:22:24.713 回答
1

上面的答案对我有用。

但我认为大多数人应该 forState:UIControlStateHighlighted改变forstate:UIControlStateSelected

于 2014-05-07T13:17:44.603 回答