如何在SpriteKit项目中使用自定义字体? - 斯威夫特

时间:2023-01-23 23:48:32

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.

我是swift的新手,我想在我的SpriteKit项目中添加一个自定义字体,然而,在环顾四周之后,我找不到解决方案。

1 个解决方案

#1


8  

  1. First of all you need to drag the font into the project.
  2. 首先,您需要将字体拖入项目中。

  3. After that you need to select the font and select the target Membership checkmark for your app as seen in the picture.
  4. 之后,您需要选择字体并为您的应用选择目标会员核对标记,如图所示。

如何在SpriteKit项目中使用自定义字体? - 斯威夫特

  1. After that you go to your Info.plist and add the Name of the font in "Fonts Provided By Application"

    之后,转到Info.plist并在“由应用程序提供的字体”中添加字体的名称

  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

    现在你终于可以使用你将使用其他所有字体的字体。如果它不能正常工作,你可以找到Xcode给出字体的名称

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.
  2. 现在只需在SKLabelNode中使用该字体即可。

#1


8  

  1. First of all you need to drag the font into the project.
  2. 首先,您需要将字体拖入项目中。

  3. After that you need to select the font and select the target Membership checkmark for your app as seen in the picture.
  4. 之后,您需要选择字体并为您的应用选择目标会员核对标记,如图所示。

如何在SpriteKit项目中使用自定义字体? - 斯威夫特

  1. After that you go to your Info.plist and add the Name of the font in "Fonts Provided By Application"

    之后,转到Info.plist并在“由应用程序提供的字体”中添加字体的名称

  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

    现在你终于可以使用你将使用其他所有字体的字体。如果它不能正常工作,你可以找到Xcode给出字体的名称

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.
  2. 现在只需在SKLabelNode中使用该字体即可。