2012-04-23 46 views
13

我已定制的TabBar外观,的iOS5的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"]]; 

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

感谢,

+1

看一看http://stackoverflow.com/a/8412083/886407 – JiaYow 2012-04-23 17:37:49

+0

哦邪恶!我试过寻找,显然不够辛苦!谢谢! – 2012-04-23 18:21:37

回答

18
[[UITabBarItem appearance] setTitleTextAttributes: 
    [NSDictionary dictionaryWithObjectsAndKeys: 
     [UIColor blackColor], UITextAttributeTextColor, 
     [UIFont fontWithName:@"font" size:0.0], UITextAttributeFont, 
     nil] 
              forState:UIControlStateHighlighted]; 
+1

请注意,这仅适用于iOS 5及以上版本 – 2012-08-17 19:25:59

+0

如何为标题设置边缘插入? – 2013-05-27 09:10:17

+0

@BurhanuddinSunelwala setTitlePositionAdjustment :(UIOffset)调整 – JerryZhou 2013-12-16 05:33:58

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

以上回答为我工作。

但我想大多数人应该改变 forState:UIControlStateHighlightedforstate:UIControlStateSelected