3

My custom TrueType font file that I brought into Xcode is not displaying correctly in the UINavigationBar. Instead of displaying the custom font, it displays the System font (Helvetica Bold).

RootViewController.m

self.title = @"Library";
    [[UINavigationBar appearance] setTitleTextAttributes:
     [NSDictionary dictionaryWithObjectsAndKeys:
      [UIColor whiteColor], UITextAttributeTextColor,
      [UIFont fontWithName:@"adellebasic_bold.ttf" size:20.0], UITextAttributeFont,nil]];

I have also made sure that I copied it into Xcode correctly and I declared it under UIAppFonts in the Info.plist file. Also note that the code works if I set it to a UIFont that is included in the iPhone SDK but not a custom font brought in.

Does anyone have the slightest idea for what I'm doing wrong here?

JDev
  • 5,168
  • 6
  • 40
  • 61

2 Answers2

3

Try this:

    NSMutableDictionary *titleBarAttributes = [NSMutableDictionary dictionaryWithDictionary: [[UINavigationBar appearance] titleTextAttributes]];

    [titleBarAttributes setValue:[UIFont fontWithName:@"adellebasic_bold" size:25.0f] forKey:UITextAttributeFont];

    [self.navigationController.navigationBar setTitleTextAttributes:titleBarAttributes];

    [self.navigationController.navigationBar setTitleVerticalPositionAdjustment:4.0f forBarMetrics:UIBarMetricsDefault];

Hope this helps.

Reno Jones
  • 1,979
  • 1
  • 18
  • 30
0

actually the font file name and the font name are two different things. Check This: iOS: How can i set a non system font family, style, size of UILabel? .

Try this name "Adelle Basic Bold".

Community
  • 1
  • 1
Blind Ninja
  • 1,063
  • 13
  • 28