UIFont fontWithName returns nil UIFont fontWithName returns nil ios ios

UIFont fontWithName returns nil


My comments were starting to get lengthy, so I've decided to submit an answer instead :)

  1. Custom fonts are only supported in iOS 3.2 and above, so make sure your Deployment Target build setting doesn't go back any farther than version 3.2.

  2. Verify that the font is included in your build target (in the "Copy Bundle Resources" build phase)

  3. Check the raw value of the key for "Fonts provided by application" to make sure it's correct. When viewing the *.plist in Xcode, right-click and choose "Show Raw Keys/Values", then verify the key is UIAppFonts.

  4. I believe iOS requires the PostScript name for a font when using fontWithName: size:, which you can find/verify by opening the font in Apple's Font Book and typing command+I.

  5. At one point, there was an issue with using custom fonts and UILabel. I am not sure if this problem still exists. The solution was to subclass UILabel and set the font therein.

If it still doesn't work, this Stack Overflow thread on custom fonts has quite a bit of info, you may have some luck there.

EDIT
There's no guarantee that I have the same font file as you, but on my machine the PostScript name is "EdwardianScriptITC"


If your font name include '-' character, replace it with space character. For instance, Arial-Bold.ttf is used like [UIFont fontWithName:"Arial Bold" size:10];


The font name to be used seems to be the "Family name" in the Font Book. I tried the PostScript name, but it does not always work. Family Name, as far as I can tell, has always worked up until now.

You can check this information, as mentioned in the above answer, inside Font Book, select the font and press cmd+I.

Hope this helps...


matomo