2012-04-23 14 views
13

He personalizado la apariencia TabBar talesIOS5 TabBar fuentes y color

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

¿Cómo definir las fuentes personalizadas y los colores de texto seleccionados y no seleccionados?

Gracias,

+1

Tenga una mirada en http://stackoverflow.com/a/8412083/886407 – JiaYow

+0

Oh malvados! Intenté buscar, ¡evidentemente no lo suficiente! ¡Gracias! –

Respuesta

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

Tenga en cuenta que esto solo funciona en iOS 5 y posteriores –

+0

cómo establecer edgeinsets para el título? –

+0

@BurhanuddinSunelwala setTitlePositionAdjustment: (UIOffset) adjustment – JerryZhou

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

La respuesta anterior está trabajando para mí.

pero creo que la mayoría de la gente debe cambiar el forState:UIControlStateHighlighted-forstate:UIControlStateSelected