2

I am trying to use a custom font in my iPhone app but somehow it does not load I believe at all in the app as a start to my problem.

I dragged and dropped the "My Font.ttf" in xcode and create the key with UIAppFonts. First question: I guess the these 2 names should be strictly identical i.e. my key must display the the exact filename and so with the extension ".ttf"...? what about if upper/lower case? what about if there are spaces in the filename...?

Then I use this:

NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];
NSLog(@"Fonts: %@", [UIFont familyNames]);
[familyNames release];

to display all the fonts and clearly see that my font is NOT there....

Then so when I use that below, nothing works (for sure):

lblSol1.font = [UIFont fontWithName:@"My Font" size:32];

(if I replace by Arial, it does work so I can only think it has to do with the loading of the font...)

I understood that the name to use with -fontWithName can be different that filename (and is actually the name of the font "fullname" when you open in the get info window). Anyway, I by now tried all combinations and can't get it to work...

(I also did deploy and build for iOS 4.o to be sure to be far from 3.2 in case of..)

Thanks for your help.

Cheers, geebee

EDIT1: the result (as asked) of showing the fonts is: Fonts: ( "Arial Hebrew", Zapfino, "Oriya Sangam MN", Cochin, Baskerville, Palatino, "Chalkboard SE", "Gurmukhi MN", Verdana, "Tamil Sangam MN", "Marker Felt", "Courier New", Courier, "Trebuchet MS", "DB LCD Temp", "Apple Color Emoji", "Arial Rounded MT Bold", "Bangla Sangam MN", "Telugu Sangam MN", "American Typewriter", Arial, Kailasa, AppleGothic, "Hiragino Kaku Gothic ProN", "Heiti SC", "Malayalam Sangam MN", Thonburi, Helvetica, Noteworthy, "Gujarati Sangam MN", "Heiti K", Futura, "Devanagari Sangam MN", "Heiti TC", "Sinhala Sangam MN", "Kannada Sangam MN", Georgia, "Heiti J", "Times New Roman", "Snell Roundhand", "Geeza Pro", "Helvetica Neue"

geebee
  • 131
  • 1
  • 11
  • what is the result of `NSLog(@"Fonts: %@", [UIFont familyNames]); ` – Robin Oct 09 '11 at 15:29
  • try to open your font with FontBook, see the top label, there is the name of the font wich may be different from the name of the .ttf – Mat Oct 09 '11 at 15:33
  • @Robin: just made an edit (EDIT1) - my font does not appear... so it is why I am left to think that the problem is really at the source and that it is simply not "loaded" however that is suppose to happen – geebee Oct 09 '11 at 15:34
  • @Mat: I indeed open FontBook and saw the name was different and used this one in the code but it is not changing my label displayed - because I believe in first place my font is not loaded "automagically" by xcode and UIAppFonts like it should - and would I believe anyway appear in the familyNames somehow... – geebee Oct 09 '11 at 15:36
  • @Mat (*2) : are you saying that in the UIAppFonts key-value, it should be the font name and not the filename? I tried that and it still does not appear with the NSLog.. familynames... – geebee Oct 09 '11 at 15:38
  • nope, the UIAppFonts key-value is the font.ttf – Mat Oct 09 '11 at 15:51
  • The UIAppFontsKey specifies an array value, that contains items that have the filename as value. Did you accidentally do a direct connection (key = UIAppFonts, value = filename)? – Tom Oct 09 '11 at 17:46
  • I try this method and it just works on iOS 5.0, can´t get it working on iOS < 5.0 – Frade Apr 02 '12 at 12:07
  • of course You have to add your font as resource and then include it to your UIAppFonts array (file name including filename extension). I'm using otf, but I think it works also with ttf – Frade Apr 02 '12 at 12:09
  • 1
    I had the same problem. Simply check that your ttf files are included in the "Copy Bundle Ressource" list under "Build Phases" of your target. I don't know why, but my ttf weren't automatically added to this list. Perhaps because there are too many items (over 700)... – Diwann Jul 04 '12 at 14:47

1 Answers1

1

According to the documentation here: UIAppFonts

UIAppFonts (Array - iOS) specifies any application-provided fonts that should be made available through the normal mechanisms. Each item in the array is a string containing the name of a font file (including filename extension) that is located in the application’s bundle. The system loads the specified fonts and makes them available for use by the application when that application is run.

This key is supported in iOS 3.2 and later.

So yes, you need to include the filename extension.

Tap Forms
  • 912
  • 8
  • 16