item color bar iphone objective-c uinavigationcontroller uinavigationbar

iphone - color - navigation controller swift 4



Cambiar la fuente de la barra de navegaciĆ³n (7)

La pregunta es simple y simple, la respuesta desafortunadamente no.

¿Cómo se puede cambiar la fuente del texto en UINavigationBar ?


A partir de iOS 5, puedes usar el proxy de apariencia.

La respuesta está en un duplicado de esta pregunta: https://.com/a/12364740/883413


Actualizado para iOS 7:

[[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys: [UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0], NSForegroundColorAttributeName, shadow, NSShadowAttributeName, [UIFont fontWithName:@"HelveticaNeue-CondensedBlack" size:21.0], NSFontAttributeName, nil]];

cortesía de:

http://www.appcoda.com/customize-navigation-status-bar-ios-7/


La respuesta anterior funciona. Agregaría la siguiente línea antes de la última línea. Si no lo hago, parece que la etiqueta está alineada en el centro incorrectamente si hay un botón de retroceso en el lado izquierdo pero no en el derecho.

... [self.navigationItem.titleView sizeToFit]; [label release]; // not needed if you are using ARC


No estoy seguro de por qué todas las respuestas incluyeron la sombra. Agregar las líneas que manipulan la sombra no hace nada con respecto a cambiar la fuente del texto. Estas 2 líneas de código funcionarán para iOS 8.4 y Swift

let attributesDictionary = [NSFontAttributeName: UIFont(name: "Helvetica Neue", size: 14)!] navigationController!.navigationBar.titleTextAttributes = attributesDictionary

titleTextAttributes almacena un diccionario que dictará la fuente, el color, el tamaño y otros atributos del título de la barra de navegación.


Si desea cambiar la fuente en el propio Interface Builder (sin ningún código), aquí está la manera de hacerlo en Xcode6:

1.) Encuentre la vista de la barra de navegación debajo de la escena del controlador de navegación

2.) Cambie los atributos de Fuente del Título, Color y Sombra en el Inspector de Atributos.


Desde iOS 7 y posterior:

NSShadow* shadow = [NSShadow new]; shadow.shadowOffset = CGSizeMake(0.0f, 1.0f); shadow.shadowColor = [UIColor redColor]; [[UINavigationBar appearance] setTitleTextAttributes: @{ NSForegroundColorAttributeName: [UIColor greenColor], NSFontAttributeName: [UIFont fontWithName:@"Helvetica" size:20.0f], NSShadowAttributeName: shadow }];

Desde iOS 5 y posterior:

[[UINavigationBar appearance] setTitleTextAttributes: @{ UITextAttributeTextColor: [UIColor greenColor], UITextAttributeTextShadowColor: [UIColor redColor], UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)], UITextAttributeFont: [UIFont fontWithName:@"Helvetica" size:20.0f] }];

Antes de iOS 5:

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 400, 44)]; label.backgroundColor = [UIColor clearColor]; label.font = [UIFont boldSystemFontOfSize:20.0]; label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5]; label.textAlignment = UITextAlignmentCenter; label.textColor =[UIColor whiteColor]; label.text=self.title; self.navigationItem.titleView = label; [label release];


NSShadow *shadow = [NSShadow new]; [shadow setShadowColor: [UIColor clearColor]]; [shadow setShadowOffset: CGSizeMake(0.0f, 1.0f)]; [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIFont fontWithName:@"TimeBurner" size:27.0f], NSFontAttributeName, [UIColor whiteColor], NSForegroundColorAttributeName, shadow, NSShadowAttributeName,nil]];