objective-c cocoa-touch fonts uinavigationbar title

objective c - ¿Cambiar las propiedades de la fuente UINavigationBar?



objective-c cocoa-touch (6)

Tengo un UINavigationBar agregado a mi vista UIViewController. Quiero cambiar las propiedades de las fuentes. Tenga en cuenta que quiero cambiar un UINavigationBar no controlador. En mi aplicación donde uso UINavigationController utilizo self.navigationItem.titleView = label; para mostrar la etiqueta personalizada.

¿Cómo puedo lograr tener un título personalizado en mi UINavigationBar?

PD: uso esto para establecer el texto del título self.navBar.topItem.title = @"Information"; de mi UINavigationBar.


Desde iOS 5 en adelante tenemos que establecer el color del texto del título y la fuente de la barra de navegación usando titleTextAttribute Dictionary (diccionario predefinido en la referencia de la clase del controlador UInavigation).

[[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys: [UIColor blackColor], NSForegroundColorAttributeName, [UIFont fontWithName:@"ArialMT" size:16.0], NSFontAttributeName,nil]];

El siguiente tutorial es el mejor tutorial para la personalización de elementos UIE como la barra de navegación UI, el control segmentado por UI, UITabBar. Esto puede ser útil para usted

http://www.raywenderlich.com/4344/user-interface-customization-in-ios-5


En iOS8 swift, use el siguiente código para establecer la fuente:

var navigationBarAppearance = UINavigationBar.appearance() let font = UIFont(name: "Open Sans", size: 17) if let font = font { navigationBarAppearance.titleTextAttributes = [NSFontAttributeName: font, NSForegroundColorAttributeName: UIColor.whiteColor()] }


No olvides agregar la fuente a tu objetivo.

Hice todo lo que se puede hacer sobre una fuente y no pude cargarla, cuando, de hecho, la fuente no era miembro de mi objetivo.

Por lo tanto, consulte la Membresía de Target también en la fuente personalizada agregada.


Solo ponga esto en el delegado de su aplicación

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

De Ray Wenderlich:

http://www.raywenderlich.com/4344/user-interface-customization-in-ios-5

[[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:@"STHeitiSC-Light" size:0.0], UITextAttributeFont, nil]];


el siguiente enlace lo ayudará. Depende de dónde le gustaría establecer las propiedades de la fuente en la barra de navegación de viewController actual en cualquier lugar de la aplicación

puedes encontrar un buen tutorial aquí% http://www.appcoda.com/customize-navigation-status-bar-ios-7/?utm_campaign=iOS_Dev_Weekly_Issue_118&utm_medium=email&utm_source=iOS%2BDev%2BWeekly

La idea básica es crear una instancia NSDictionary y llenarla con la fuente deseada y otras propiedades. Terminé con esta solución:

en su método de controlador viewDidLoad después de [super viewDidLoad], coloque estas líneas:

UIColor *color = [UIColor redColor]; NSShadow *shadow = [NSShadow new]; UIFont *font = [UIFont fontWithName:@"EnterYourFontName" size:20.0] shadow.shadowColor = [UIColor greenColor]; shadow.shadowBlurRadius = 2; shadow.shadowOffset = CGSizeMake(1.0f, 1.0f); //fill this dictionary with text attributes NSMutableDictionary *topBarTextAttributes = [NSMutableDictionary new]; //ios 7 topBarTextAttributes[NSForegroundColorAttributeName] = color; //ios 6 topBarTextAttributes[UITextAttributeTextColor] = color; //ios 6 topBarTextAttributes[UITextAttributeTextShadowOffset] = [NSValue valueWithCGSize:shadow.shadowOffset]; topBarTextAttributes[UITextAttributeTextShadowColor] = shadow.shadowColor; //ios 7 topBarTextAttributes[NSShadowAttributeName] = shadow; //ios 6 topBarTextAttributes[UITextAttributeFont] = font; //ios 7 topBarTextAttributes[NSFontAttributeName] = font; //for all the controllers uncomment this line // [[UINavigationBar appearance]setTitleTextAttributes:topBarTextAttributes]; //for current controller uncoment this line // self.navigationController.navigationBar.titleTextAttributes = topBarTextAttributes;


(Esto no es posible con la nueva API de Apariencia iOS 5.0).

Editar:

iOS> = 5.0:

Establezca los atributos de texto del título para la barra de navegación:

// Customize the title text for *all* UINavigationBars NSDictionary *settings = @{ UITextAttributeFont : [UIFont fontWithName:@"YOURFONTNAME" size:20.0], UITextAttributeTextColor : [UIColor whiteColor], UITextAttributeTextShadowColor : [UIColor clearColor], UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetZero]}; [[UINavigationBar appearance] setTitleTextAttributes:settings];

iOS <5.0

UINavigationItem no tiene una propiedad llamada etiqueta o algo, solo un titleView. Solo puede establecer la fuente estableciendo una etiqueta personalizada como esta vista de título. Puede usar el siguiente código: (como se sugiere here )

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 44)]; label.font = [UIFont fontWithName:@"YOURFONTNAME" size:20.0]; label.shadowColor = [UIColor clearColor]; label.textColor =[UIColor whiteColor]; label.text = self.title; self.navigationItem.titleView = label; [label release];