Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIFont fontWithName returns nil

In my info.plist, I added a key "Fonts provided by application" and added EdwardianScriptITCStd.otf enter image description here

But, when I try to get that font, it returns nil:

NSLog(@"%@", [UIFont fontWithName:@"EdwardianScriptITCStd"                                  size:16.0f]); 

I printed the font families using [UIFont familyNames] and it's not there either:

(     Thonburi,     "Snell Roundhand",     "Academy Engraved LET",     "Marker Felt",     "Geeza Pro",     "Arial Rounded MT Bold",     "Trebuchet MS",     Arial,     Marion,     "Gurmukhi MN",     "Malayalam Sangam MN",     "Bradley Hand",     "Kannada Sangam MN",     "Bodoni 72 Oldstyle",     Cochin,     "Sinhala Sangam MN",     "Hiragino Kaku Gothic ProN",     Papyrus,     Verdana,     "Zapf Dingbats",     Courier,     "Hoefler Text",     "Euphemia UCAS",     Helvetica,     "Hiragino Mincho ProN",     "Bodoni Ornaments",     "Apple Color Emoji",     Optima,     "Gujarati Sangam MN",     "Devanagari Sangam MN",     "Times New Roman",     Kailasa,     "Telugu Sangam MN",     "Heiti SC",     "Apple SD Gothic Neo",     Futura,     "Bodoni 72",     Baskerville,     "Chalkboard SE",     "Heiti TC",     Copperplate,     "Party LET",     "American Typewriter",     "Bangla Sangam MN",     Noteworthy,     Zapfino,     "Tamil Sangam MN",     "DB LCD Temp",     "Arial Hebrew",     Chalkduster,     Georgia,     "Helvetica Neue",     "Gill Sans",     Palatino,     "Courier New",     "Oriya Sangam MN",     Didot,     "Bodoni 72 Smallcaps" ) 

What am I missing? Thanks!

like image 533
0xSina Avatar asked Apr 21 '12 00:04

0xSina


2 Answers

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"

like image 158
inspector-g Avatar answered Sep 27 '22 03:09

inspector-g


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];

like image 27
BeyazBaron Avatar answered Sep 26 '22 03:09

BeyazBaron