2012-06-12 26 views

Respuesta

66

Esto funcionó:

NSDictionary *textTitleOptions = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor darkGrayColor], UITextAttributeTextColor, [UIColor whiteColor], UITextAttributeTextShadowColor, nil]; 
[[UINavigationBar appearance] setTitleTextAttributes:textTitleOptions]; 
+5

Debe aceptar su propia respuesta. –

+0

muy útil .. gracias –

+2

Funciona bien. Si es necesario configurar también el tema de la UINavigationBar activo, añada esta línea: '[yourViewController.navigationController.navigationBar setTitleTextAttributes: textTitleOptions]' –

3

que se estrella antes de la aplicación UINavigationBar no tiene un título o estado ... Esos son los métodos UIButton

Es necesario

[[UINavigationBar appearance] setTintColor:[UIColor darkGrayColor]]; 
+0

No, eso no funciona. Creo que es para teñir el bar en sí. Ya estamos usando el método setBackgroundImage: para cambiar el fondo de la barra de navegación, por lo que ahora necesito cambiar el color del texto de blanco a gris oscuro para que sea legible. – RyJ

+0

Lo siento, no sabía que estabas tratando de establecer el color de texto navBar. pensé que solo estabas tratando de cambiar su color. –

2

La @ La respuesta de RyJ es genial y funcionó para mí. Pensé que había CHIP en que hay un buen tutorial sobre esto en el sitio de Ray Wenderlich, titulado (el interior):

User Interface Customization in iOS 6

Vea la sección Personalización UINavigationBar

He aquí el fragmento de código de el título de la barra de navegación, para cambiar a nivel mundial:

// Customize the title text for *all* UINavigationBars 
[[UINavigationBar appearance] setTitleTextAttributes: 
[NSDictionary dictionaryWithObjectsAndKeys: 
    [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0], 
    UITextAttributeTextColor, 
    [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8], 
    UITextAttributeTextShadowColor, 
    [NSValue valueWithUIOffset:UIOffsetMake(0, -1)], 
    UITextAttributeTextShadowOffset, 
    [UIFont fontWithName:@"Arial-Bold" size:0.0], 
    UITextAttributeFont, 
    nil]]; 

otro punto menor es que parece que hay una sombra por defecto en la barra de título, por lo que deshacerse de él, no puedes simplemente eliminar el atributo. En su lugar, debe establecer un desplazamiento sombreado:

UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetMake(0, 0)] 
0

Utilicé el siguiente código para cambiar el color de la barra de título.

NSShadow *shadow = [[NSShadow alloc] init]; 
shadow.shadowColor = [UIColor blackColor]; 
shadow.shadowOffset = CGSizeMake(1, 0); 

NSDictionary *titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor], 
              NSShadowAttributeName:shadow}; 

[[UINavigationBar appearance] setTitleTextAttributes:titleTextAttributes]; 
4

Aquí hay un ejemplo de cómo hacer esto en Swift:

UINavigationBar.appearance().titleTextAttributes = 
    [NSFontAttributeName:UIFont(name:"Exo2-Bold", size: 18) as! AnyObject, 
    NSForegroundColorAttributeName:UIColor.whiteColor()] 
0

Utilizando la sintaxis moderna y código que realmente funciona, así es como globalmente el estilo de su texto UINavigationBar título:

NSShadow *navigationBarTitleShadow = [[NSShadow alloc] init]; 
navigationBarTitleShadow.shadowColor = [UIColor colorWithWhite:0.5 
                 alpha:0.5]; 
navigationBarTitleShadow.shadowOffset = CGSizeMake(2.0, 2.0); 
[[UINavigationBar appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor blackColor], 
                 NSFontAttributeName : [UIFont fontWithName:@"Arial-BoldMT" 
                           size:30.0], 
                 NSShadowAttributeName : navigationBarTitleShadow }]; 

Nota: NSShadow 's shadowBlurRadius no se respeta la propiedad.

Nota: Las sombras son tan iOS 6. Nunca las use.

Cuestiones relacionadas