How to use Helvetica Neue UltraLight (and other fonts) in your iOS Code

One of the more frustrating things about doing things in code is when it comes to fonts. Lately I had to do a guessing game when I wanted to use Helvetica Neue UltraLight as a font in a demo for an upcoming blog post for Cloud City Development, and it was making me crazy playing the “guess the font name in code” game:

“Helvetica Neue Ultra Light”? Nope.
“Helvetic-Neue-Ultra-Light”? Nope.
“Helvetica-Neue-UltraLight”? Nope.
“HelveticaNeue-Ultra-Light”? Nope.
“HelveticaNeue-UltraLight”? BINGO!

It took me a few tries through the trial-and-error method, but I eventually got the right name (as you can see from the list above, it’s “HelveticaNeue-UltraLight”), but it led me to think there must be an easier way.

Enter Font Book.

Font Book is an application that comes with Mac OS X for managing fonts in your system, and it turns out that it can help us as developers to solve these kinds of riddles. The challenge is that the answers are little a bit buried…

So… let’s go through this particular challenge.

First, let’s open Font Book (Look in Applications > Font Book, or if you’re an Alfred or Spotlight search user just start typing “Font Book” and it should pick it up immediately).

When you launch FontBook, it will probably look something like this (select “All Fonts” from the sidebar if it’s not already selected):

Then, the next step is to scroll down and find “Helvetica Neue” in the list of font names, and then expand it and select “UltraLight” node in the list:

If we examine the details in panel on the right, the item we are most interested in is the PostScript name entry, since this is the one that we will use in our code.

As you can see here, the value is “HelveticaNeue-UltraLight”:

We can actually highlight and copy it directly from the detail panel. Very convenient.

Now that that’s done, it’s basically just a matter of plugging in the new value into your code:

myLabel.font = [UIFont fontWithName:@"HelveticaNeue-UltraLight" size:128.0];

myLabel.font = UIFont(name: "HelveticaNeue-UltraLight", size: 128.0)

…and that’s it! Mystery solved!