2012-04-23 47 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