1

How to add a custom font to storyboard in Mac app development. I went through some blogs and tried by adding font book and develop one NStextfield using this custom font using storyboard. But it is system dependent. I created the DMG and install in another computer it uses the default font. I did it programmatically, but my requirement is through storyboard. Please help me on this

Jio
  • 1,146
  • 1
  • 9
  • 22
  • would the answers [to this duplicate question](https://stackoverflow.com/questions/27680893/how-to-use-custom-fonts-in-a-mac-application) help you out? – Michael Dautermann Jun 27 '17 at 19:06
  • I tried as they said but fails. It works only programmatically, not through story board – Jio Jun 27 '17 at 19:10
  • I don't see anything programmatically about that related question. You simply need to add the fonts to your project, modify your Info.plist file to indicate what fonts are custom, and if you actually want to *see* the fonts in your storyboard, that's when you add the font to your fontbook. If you set your label or textfield to that font in your storyboard, it should appear in the finished app. – Michael Dautermann Jun 27 '17 at 19:14
  • Nope. I tried it. If you install the fonts in the system and add custom fonts to project and modify info plist it will show in the storyboard . But when we move the app to another system as .app or dmg, it will show the default font only. Because the system don't know the font. – Jio Jun 27 '17 at 19:17
  • If you go to your built app and do a command-click to "show package contents" on the app, look inside the various subfolders (e.g. Resources), do you see that embedded font file? – Michael Dautermann Jun 27 '17 at 19:23
  • Yes.it is there. – Jio Jun 27 '17 at 19:25

1 Answers1

4

I spent a bit of time trying to figure this out and found the solution in this related question.

In your info.plist file, which you made available to me at

Info.plist file

It turns out you can safely get rid of the "Fonts Provided By Application" section (it's an iOS specific key and is ignored by macOS).

And for "Application Fonts resource path", make certain you have the font going into a "Fonts" folder (or some subfolder within your application bundle's Resources folder).

Lastly, do a custom copy build phase like this:

embed font into application bundle

This is copying the font into the "Fonts" subfolder specified in your "Application Fonts resource path". You don't want the font in your Resources folder, but you do want it in a subfolder underneath Resources.

Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215