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:
- Copy the font file (usually a .ttf file) into xcode. I like to put mine in Supporting Files/Fonts/
- 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
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.
UnicodeThis 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.
LigatureIn 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:
If you have any questions on the topic, feel free to email me or ping me on twitter.