Milese3
Milese3

Reputation: 343

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.

Upvotes: 9

Views: 4320

Answers (1)

Devapploper
Devapploper

Reputation: 6192

  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.

Upvotes: 13

Related Questions