Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 867
Gasim Avatar asked Mar 04 '15 18:03

Gasim


1 Answers

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)

Swift:

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

Objective-C:

[[UINavigationBar appearance] setTitleTextAttributes: 
    [NSDictionary dictionaryWithObjectsAndKeys: 
        [UIColor whiteColor], NSForegroundColorAttributeName, 
           [UIFont fontWithName:@"LeagueGothic-Regular" size:16.0], NSFontAttributeName,nil]];
like image 165
Chao Wang Avatar answered Sep 22 '22 18:09

Chao Wang