I am new to swift, and I'd like to add a custom font to my SpriteKit project, however, after looking around, I cannot find a solution.
Asked
Active
Viewed 4,003 times
9
-
1[SpriteKit does not make any difference](http://stackoverflow.com/questions/21737788/custom-fonts-in-ios-7). – Kreiri Aug 11 '14 at 11:19
-
2Okay- but I still don't understand how to add custom fonts with iOS 8 & Swift. – Milese3 Aug 11 '14 at 12:36
-
1I imagine the process would be similar to http://stackoverflow.com/q/21737788/ – hlfcoding Aug 14 '14 at 08:48
1 Answers
13
- First of all you need to drag the font into the project.
- After that you need to select the font and select the target Membership checkmark for your app as seen in the picture.
After that you go to your Info.plist and add the filename of the font (with extension) in "Fonts Provided By Application"
Now you can finally use the font als you would use every other font. If it doesn't work as it should you can find out the name Xcode gave the font with
Swift:
for name in UIFont.familyNames() {
println(name)
if let nameString = name as? String{
println(UIFont.fontNamesForFamilyName(nameString))
}
}
Swift 3:
for name in UIFont.familyNames {
print(name)
if let nameString = name as? String {
print(UIFont.fontNames(forFamilyName: nameString))
}
}
- Now just use the font for example in your SKLabelNode.

Tim
- 14,447
- 6
- 40
- 63

Devapploper
- 6,062
- 3
- 20
- 41
-
That target tick is exactly what I was missing! Thank you for saving my head from hitting against a wall. – Alexey Sobolevsky Oct 22 '16 at 18:38
-
-
Your Swift 3 version still works in Swift 5. Needed to find out the name assigned, used what was in ["FontNamedHere"], Thank you. – Brian M May 24 '20 at 18:27