0

How do I change the font of a Large Titled Navigation Bar in Swift?

I was unable to find a thread which covered implementing custom fonts for a navigation bar with a large title.

I am trying to use the font titled: "ヒラギノ角ゴシック W8.ttc". This appears to be pre-installed on my Mac. The name in the Font Book is: "Hiragino Kaku Gothic StdN".

This is what I have tried:

self.navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedString.Key.font: UIFont(name: "ヒラギノ角ゴシック-W8", size: 20)!]

and

self.navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedString.Key.font: UIFont(name: "ヒラギノ角ゴシックW8", size: 20)!]

and

self.navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedString.Key.font: UIFont(name: "Hiragino Kaku Gothic StdN", size: 20)!]

Font The "W8" is the Bold version of this font.

Is the problem that the font file name is in a different language or is it something else?

Ryan
  • 107
  • 7
  • 30
  • 1
    Why does your iOS device care about which font family is loaded on your desktop computer? – El Tomato Mar 29 '19 at 04:14
  • You need to add the font files to your iOS project. I would suggest you try with existing different fonts available on iOS to experiment. – Aks Mar 29 '19 at 04:46

2 Answers2

14

Please check the images how to add font in <code>info.plist</code>

Fist make sure that your font is .ttf or .otf format

1) Import your font into the project 2) Add new key "Fonts provided by application" on application's info.plist file and add your font names Now you can use custom fonts with interface builder or programatically

navigationController?.navigationBar.largeTitleTextAttributes =
    [NSAttributedStringKey.foregroundColor: UIColor.blue,
     NSAttributedStringKey.font: UIFont(name: "your font name", size: 30) ??
                                 UIFont.systemFont(ofSize: 30)]
Vijay Kahar
  • 1,082
  • 1
  • 7
  • 20
0

Latest swift version:

navigationController?.navigationBar.largeTitleTextAttributes =
        [NSAttributedString.Key.foregroundColor: backIconColor,
         NSAttributedString.Key.font: UIFont(name: "your font name", size: 30) ??
                                     UIFont.systemFont(ofSize: 30)]
Umair Ali
  • 758
  • 8
  • 17