Swift – Using custom fonts in Xcode 6 – Swift

swift

I'm new to Swift! I'd like to know how I can use custom fonts in my swift application in Xcode 6.

Best Solution

You just drag the font file (.ttf) into the resources area on the left pane of Xcode.

When you drop it in, a dialog box will appear. Make sure the target for your application checkbox is checked. Then add the following key to your plist:

Fonts provided by application

With the values of the filename "myFont.ttf"


UPDATE (see comment below)

Also make sure the font is added to the Copy Bundle Resources (found under Target -> Build Phases) I just spent about an hour on this, and I was the one who answered this question months ago lol.


UPDATE

Another helpful tip to find the name of the font for the font-family if you are using CSS is to run the following command:

NSLog("Available fonts: %@", UIFont.familyNames());

It prints out all the font name available to the system, including the ones you custom added.