iphone ios objective-c uinavigationbar ios7

iphone - IOS 7 Barra de navegación texto y color de flecha



objective-c uinavigationbar (10)

Creo que las respuestas anteriores son correctas, esta es otra forma de hacer lo mismo. Lo estoy compartiendo aquí con otros, por si acaso se vuelve útil para alguien. Así es como puede cambiar el color del texto / título de la barra de navegación en ios7:

UIColor *red = [UIColor colorWithRed:254.0f/255.0f green:0.0f/255.0f blue:0.0f/255.0f alpha:1.0]; NSMutableDictionary *navBarTextAttributes = [NSMutableDictionary dictionaryWithCapacity:1]; [navBarTextAttributes setObject:red forKey:NSForegroundColorAttributeName ]; self.navigationController.navigationBar.titleTextAttributes = navBarTextAttributes;

Quiero configurar el fondo para que la barra de navegación sea negra y todos los colores dentro de ella sean blancos .

Entonces, utilicé este código:

[[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys: [UIColor whiteColor], NSForegroundColorAttributeName, [UIColor whiteColor], NSForegroundColorAttributeName, [NSValue valueWithUIOffset:UIOffsetMake(0, -1)], NSForegroundColorAttributeName, [UIFont fontWithName:@"Arial-Bold" size:0.0], NSFontAttributeName, nil]];

Pero el color del texto del botón Atrás, la flecha y el botón de la barra tienen un color azul predeterminado.
¿Cómo cambiar esos colores como en la imagen de abajo?


El comportamiento de algunas de las propiedades de UINavigationBar ha cambiado de iOS 7 . Se puede ver en la imagen que se muestra a continuación:

Dos hermosos enlaces que me gustaría compartir con ustedes. Para más detalles puedes ir a través de estos enlaces:

  1. iOS 7 UI Transition Guide .
  2. Cómo actualizar su aplicación para iOS 7 .

Documentación de Apple para barTintColor dice:

Este color se hace translúcido de forma predeterminada a menos que establezca la propiedad translúcida en NO.

Código de muestra :

self.navigationController.navigationBar.barTintColor = [UIColor blackColor]; self.navigationController.navigationBar.tintColor = [UIColor whiteColor]; [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}]; self.navigationController.navigationBar.translucent = NO;


La respuesta de Vin funcionó muy bien para mí. Esta es la misma solución para los desarrolladores de C # que utilizan Xamarin.iOS / MonoTouch:

var navigationBar = NavigationController.NavigationBar; //or another reference navigationBar.BarTintColor = UIColor.Blue; navigationBar.TintColor = UIColor.White; navigationBar.SetTitleTextAttributes(new UITextAttributes() { TextColor = UIColor.White }); navigationBar.Translucent = false;


Para cambiar el color del título de UINavigationBar la manera correcta, use este código:

[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor]];

UITextAttributeTextColor está en desuso en la última versión de ios 7. Utilice NSForegroundColorAttributeName en NSForegroundColorAttributeName lugar.


Parece que los controles de Accessibility en la iOS Settings anulan casi todo lo que intentas hacer con el color en los botones de la barra de navegación. Asegúrese de tener todas las configuraciones en las posiciones predeterminadas (establecer aumentar el contraste, el texto en negrita , las formas de los botones, etc. para que estén desactivadas) de lo contrario no verá ningún cambio. Una vez que lo hice, todo el código de cambio de color comenzó a funcionar como se esperaba. Puede que no tenga que apagarlos a todos, pero no lo seguí.


Si está buscando cambiar el tamaño del texto del título y el color del texto, debe cambiar el Título del texto del NSDictionaryTttributos, para 2 de sus objetos:

self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"Arial" size:13.0],NSFontAttributeName, [UIColor whiteColor], NSForegroundColorAttributeName, nil];


Swift / iOS8

let textAttributes = NSMutableDictionary(capacity:1) textAttributes.setObject(UIColor.whiteColor(), forKey: NSForegroundColorAttributeName) navigationController?.navigationBar.titleTextAttributes = textAttributes


Swift3, ios 10

Para asignar globalmente el color, en AppDelegate didFinishLaunchingWithOptions :

let textAttributes = [NSForegroundColorAttributeName:UIColor.white] UINavigationBar.appearance().titleTextAttributes = textAttributes

Swift 4, iOS 11

let textAttributes = [NSAttributedStringKey.foregroundColor:UIColor.white] UINavigationBar.appearance().titleTextAttributes = textAttributes


Este me tomó cerca de medio día para averiguarlo, pero esto es lo que me funcionó. Dentro del rootViewController que inicializa navigationController, coloco este código dentro de mi método viewDidAppear:

//set bar color [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:85.0/255.0 green:143.0/255.0 blue:220.0/255.0 alpha:1.0]]; //optional, i don''t want my bar to be translucent [self.navigationController.navigationBar setTranslucent:NO]; //set title and title color [self.navigationItem setTitle:@"Title"]; [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor]]; //set back button color [[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], UITextAttributeTextColor,nil] forState:UIControlStateNormal]; //set back button arrow color [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];

Mi post completo sobre esto here


[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];