【问题标题】:Adding custom font to SpriteKit with Swift 3.0使用 Swift 3.0 向 SpriteKit 添加自定义字体
【发布时间】:2017-05-21 18:26:47
【问题描述】:

我似乎无法添加我的自定义字体。我已将其拖入我的项目中,并将其作为目标添加到我的项目中。

创建标签的代码如下:

// Create Unlock Text
func createUnlockText() {
    unlockText = SKLabelNode(fontNamed: "04b_19")
    unlockText.name = "unlockText"
    unlockText.text = "Goal: \(goalScore)"
    unlockText.fontSize = 100     
    unlockText.fontColor = SKColor(red: 100.0, green: 100.0, blue: 255.0, alpha: 1.0)
    unlockText.position = CGPoint(x: 0, y: (self.frame.size.height / 2.8))
    unlockText.zPosition = 1
    self.addChild(unlockText)
}    

我在 plist 中添加了应用程序提供的字体,所以我很困惑:(

【问题讨论】:

  • 这与您在UIKit 中添加自定义字体的过程相同。查看这篇文章并确保您已完成所有步骤:codewithchris.com/…
  • 尝试使用这个 'SKLabelNode(fontNamed: "04b 19")' 而不是 SKLabelNode(fontNamed: "04b_19")

标签: ios swift swift3 custom-font


【解决方案1】:

以下是添加自定义字体的步骤:

  1. 将文本字体拖放到项目中。 (你已经做到了)
  2. 添加 info.plist(你已经完成了)
  3. 检查源是否在相应的目标中。选择字体并在右侧菜单中列出目标,检查它 出去。
  4. 在项目中,在第一个文件夹中,转到“Build Phases”>“Copy Bundles”并检查是否已添加,如果没有,请添加。
  5. 验证字体名称是否正确。

使用它是这样完成的:

  1. 您可以在视图控制器的情节提要中选择它。
  2. 按代码:

    label.font = UIFont(name: "Montserrat-Light", size: 12.0)

然后在SpriteKit中,都是一样的步骤,但是代码是这样的:

SKLabelNode(fontNamed: "Montserrat Light")

【讨论】:

    猜你喜欢
    • 2016-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多