Gasim Gasim -4 years ago 144
iOS Question

Title Font doesn't change in Navigation Bar

I have a controller that is embedded in a Navigation Controller and I want to change the font of the title in the navigation bar. I want to use the storyboard, so it changes across the app (instead of creating a file for NavigationController and doing it via code); not per controller: Storyboard

I am able to change the font size and color but I am not able to change the font family when using a custom font. All other Xcode fonts work in this case. I use the custom font everywhere in the app but it only doesn't work in case of Navigation.

What can be the reason for this problem?

Answer Source

I have the exactly same problem in Xcode 6.4. This might be a bug of Xcode.

For now, what you can do is to set custom font programmatically. (Make sure you have your font ttf file in your project and add a property in Project Setting -> Info -> Fonts provided by application)


self.navigationController?.navigationBar.titleTextAttributes = [ NSFontAttributeName: UIFont(name: "LeagueGothic-Regular", size: 16.0)!, 
                                                                 NSForegroundColorAttributeName: UIColor.whiteColor()]


[[UINavigationBar appearance] setTitleTextAttributes: 
    [NSDictionary dictionaryWithObjectsAndKeys: 
        [UIColor whiteColor], NSForegroundColorAttributeName, 
           [UIFont fontWithName:@"LeagueGothic-Regular" size:16.0], NSFontAttributeName,nil]];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download