Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use a custom font in a SpriteKit project? - Swift

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.

like image 446
Milese3 Avatar asked Aug 11 '14 11:08

Milese3


1 Answers

  1. First of all you need to drag the font into the project.
  2. After that you need to select the font and select the target Membership checkmark for your app as seen in the picture.

Xcode window with selected target membership for the custom font

  1. After that you go to your Info.plist and add the filename of the font (with extension) in "Fonts Provided By Application"

  2. 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))
    }
}
  1. Now just use the font for example in your SKLabelNode.
like image 121
Devapploper Avatar answered Oct 11 '22 12:10

Devapploper