2014-05-12 7 views
0

J'utilise le UIAppearance pour modifier les attributs de mon titre dans la barre de navigation comme ceci:Existe-t-il un moyen de changer le titre de la barre de navigation en Italique, Gras et souligné sans changer de police?

[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [MM mainTitleColor]}]; 

Mais je n'ai pas trouvé le moyen de rendre le texte souligné ou en italique, est-il un moyen de le faire sans changer la police tous ensemble?

Répondre

1

Non. Ces propriétés ne peuvent pas être modifiées à moins que vous ne changiez de police. Parce que les clés disponibles sous le proxy apparence sont

  • UITextAttributeFont
  • UITextAttributeTextColor
  • UITextAttributeTextShadowColor
  • UITextAttributeTextShadowOffset

Modifier ces propriétés pour personnaliser le UINavigationBar

Si vous cherchez un changement de police, puis voir l'exemple ci-dessous

[[UINavigationBar appearance] setTitleTextAttributes:@{ 
    UITextAttributeTextColor: TEXT_COLOR, 
    UITextAttributeTextShadowColor: SHADOW_COLOR, 
    UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0, -1)], 
    UITextAttributeFont: [UIFont fontWithName:@"Arial-Bold" size:0.0], 
}]; 
0

Essayez celui-ci. Vous devez personnaliser votre contrôleur de navigation en ajoutant un imageview.

UIFont *yourFont = [UIFont fontWithName:@"Helvetica-BoldOblique" size:[UIFont systemFontSize]]; 

if ([[UINavigationBar class]respondsToSelector:@selector(appearance)]) { 
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"myimage.png"] forBarMetrics:UIBarMetricsDefault]; 
} 

[[UINavigationBar appearance] setTitleTextAttributes:@{ 
UITextAttributeTextColor : [UIColor clearColor], 
UITextAttributeTextShadowColor : [UIColor blackColor], 
UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetMake(1, 0)], 
UITextAttributeFont : yourFont 
}]; 

Vous pouvez utiliser:

  • Optima-BoldItalic
  • TimesNewRomanPS-BoldItalicMT
  • Baskerville-BoldItalic
  • HelveticaNeue-BoldItalic
  • TrebuchetMS-Bold
  • Helvetica-BoldOblique
0

Vous pouvez ci-dessous le code pour rendre votre texte en italique et en gras.

NSShadow *shadow = [[NSShadow alloc] init]; 
     shadow.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8]; 
     shadow.shadowOffset = CGSizeMake(0, 1); 
     [[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-BoldItalic" size:21.0], NSFontAttributeName, nil]]; 

     [self setTitle:@"Title text"]; 
Questions connexes