16

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

esqew
  • 42,425
  • 27
  • 92
  • 132
Milese3
  • 343
  • 1
  • 3
  • 7
  • 2
    Woah, okay- but seriously, I'm new. I didn't know- someone removed the Xcode tag. There's no reason to down-vote it. – Milese3 Aug 13 '14 at 16:52
  • The "swift" in the title and tag are redundant but the "xcode 6" is useful because with xcode 6 there is no need to mess around with the plist anymore, making previous answers obsolete. – Cymric Dec 31 '14 at 10:14
  • 2
    the linked thread is cluttered, has a lots of outdated information and does not contain swift as a language. Meaning: not a real answer. How old an cluttered has an answer to become to not be a duplicate? – brainray Apr 23 '15 at 10:07
  • 1
    Please reopen this question. The supposed duplicate is a mess of outdated answers and objective c. It is very difficult to find a good Swift answer. – Suragch Jun 27 '15 at 01:45

1 Answers1

32

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.

quemeful
  • 9,542
  • 4
  • 60
  • 69
  • 6
    I was able to access the font from the interface builder, but fail when using it in code. Turn out that the fonts must be added to targets->Build Phase ->Copy Bundle Resources too (http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/) – Cymric Dec 31 '14 at 10:46