Matthew Conlen is a data journalist and computer scientist currently working on Realtime, an automated data-journalism platform. Matthew previously worked at Our World in Data, The New York Times, and FiveThirtyEight. He received his Ph.D. from the University of Washington where he was advised by Jeffrey Heer in the Interactive Data Lab.
Writing
Using Symbolset font on iOS
March, 2013

As an iOS and icon-font novice, I had a tough time getting our projects symbol set icons to work properly on iOS. The following serves a tutorial to those attempting to do the same.


1. Include the font in your project

The first step to using any custom font with iOS is to include it in the project. You need to do two things: 
  1. Copy the font file (usually a .ttf file) into xcode.  I like to put mine in Supporting Files/Fonts/
  2. Add the font to the .plist file: to do this, Use the key "Fonts provided by application" and set it to an array. Add an entry to this array for each font file you want to add, with type string and value <filename>. For example, my symbolset entry was named, Item 0, type String, value ss-standard.ttf.

2. Set the font on your UILabel

You can do this using a css toolkit like nativecss, or nui, or just by doing it in code
If you aren't sure about the name of the font or font family that you have available, you can include this snippet in your app delegate didFinishLaunchingWithOptions method:


3. Include a ligature or unicode character

Symbolset includes methods to insert the symbols via unicode or via ligatures. Below I show the two ways to do this. The preferable method is up to you.

Unicode
This is done with code like this:

self.myUILabel.text = @"U0001F44E"

Note that for this to work properly, you will have to ensure that there are always 8 characters after the U. Thanks to Brendan O'Brien for pointing this out.

Ligature
In order to use this method, you will have to add CoreText to your project and include the line 

#import <CoreText/CoreText.h>

at the top of your file. The trick here is to tell iOS to use any available ligature, by setting the kCTLigatureAttributeName attribute to 2. This is done with the following code:


Thanks to Kyle Rosenbluth for discussing this method.


If you have any questions on the topic, feel free to email me or ping me on twitter.