3

I need OpenSans in my app and so I imported the whole OpenSans bunch which includes Bold, ExtraBold, Italic, Regular, Light and more. I added them to Fontbook (to check the exact name I need to address them by when using them) on my Mac, to my project in the file structure and added them in Build phases to my project as well.

Now the weird thing; when I use them with UIFont, ONLY OpenSans-Bold works. The rest doesn't work. If I use OpenSans-Bold (exactly the identifier given by Fontbook), everything works fine. If I, however, change it to OpenSans-Regular or OpenSans-Light or something else in that family, I get the systemfont with UIFont and I get nothing when drawing with Quartz.

All fonts are in all lists and I checked all the identifiers from Fontbook (which was why I couldn't get OpenSans-Bold working), but now i'm at a loss. Any idea what I could be doing wrong?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
CharlesS
  • 1,563
  • 2
  • 18
  • 31
  • Please show some code. Also check out this answer to list the font names: http://stackoverflow.com/a/15985120/168493 – Marcus Adams Aug 02 '13 at 16:51
  • He's using a custom font available from Google (http://www.google.com/fonts/specimen/Open+Sans) – runmad Aug 02 '13 at 17:48
  • for me only OpenSans-Regular is working. I'm setting a label's font in the storyboard and when I use italic or bold the result is just the default font. – Claus Dec 10 '14 at 16:45

3 Answers3

14

OpenSans Regular is just OpenSans, semi-bold is OpenSans-Semibold, etc.

In Font Book.app select the font and choose Command + I which brings up the font info. In the "PostScript name" in the top you can see what the font is called and how you can call it in your code.

Also, just make sure the font has actually been added in your bundle and your plist :)

runmad
  • 14,846
  • 9
  • 99
  • 140
  • Thanks, let me try this again. I'm sure I did, but maybe I was sloppy. Why did they make this so... Anyway. Will report back. – CharlesS Aug 04 '13 at 10:41
0

You Can check the fonts provided by the ttf file With the following lines of code..

this method is provided by the UIFont class.

  • (NSArray *)fontNamesForFamilyName:(NSString *)familyName
Bharath
  • 314
  • 2
  • 8
0

You need to add the files in the right locations, then in the plist file, then enumerate them all and print them to get the PDF names so you can access them. Most likely you're using the wrong names. Fonts have three kinds of names:

  • The file name
  • The font name in Font Book
  • The PDF name - this is the one you use to access the font in code

See this answer: Adding custom fonts to iOS app finding their real names

Community
  • 1
  • 1
n13
  • 6,843
  • 53
  • 40