PIXEL
DOCK

I like the smell of Swift in the morning…

UIFont: Problem when using more than 2 custom fonts of the same Font Family.

Posted: | Author: | Filed under: iOS | Tags: , | 4 Comments »

When you add custom fonts to your iPhone or iPad App you might experience the following problem: If you add more than 2 font variants of the same font family (e.g. “Normal”, “Bold” and “Extended”), only the last two font variants that you added to the project will be usable. The first variant (the one on top of your list) just won’t show up and is replaced by one of the two variants that were added last to the project.

The reason is quite simple: The iOS SDK apparently allows only 2 custom fonts of the same font family!

As a solution you could change the font-family of your font, so that not more than two font variants have the same font-family. Just to be clear: it’s not enough to change the file name of your font. You have to change all the references to the font-family inside your font files.

You can do this with with fontforge. Fontforge requires that you installed the X11 server on your system, but that should not be a problem as it is automatically installed when you install Xcode.

Make sure that you find all references to the font family name after you opened the font in Fontforge:

  1. Open your Font in Fontforge
  2. Goto ‘Element’ -> ‘Font Info’ and change the ‘Family Name’ field
  3. Goto ‘Element’ -> ‘TTF Names’ and change the fields ‘Family’ and ‘Preferred Family’
  4. Goto ‘File’ -> ‘Generate Fonts’ and save your edited font

With this little trick you should be able to use more than two variants of one font.