I'm new to Swift! I'd like to know how I can use custom fonts in my swift application in Xcode 6.
- 2Woah, okay- but seriously, I'm new. I didn't know- someone removed the Xcode tag. There's no reason to down-vote it.Milese3– Milese32014-08-13 16:52:57 +00:00Commented Aug 13, 2014 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– Cymric2014-12-31 10:14:37 +00:00Commented Dec 31, 2014 at 10:14
- 2the 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– brainray2015-04-23 10:07:35 +00:00Commented Apr 23, 2015 at 10:07
- 1Please 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– Suragch2015-06-27 01:45:47 +00:00Commented Jun 27, 2015 at 1:45
1 Answer
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.