gpt4 book ai didi

ios - 使用 Swift 3.0 将自定义字体添加到 SpriteKit

转载 作者:行者123 更新时间:2023-11-28 06:19:28 28 4
gpt4 key购买 nike

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

创建标签的代码如下:

// 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)
}

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

最佳答案

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

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

要使用它是这样完成的:

  1. 您可以在 View Controller 的 Storyboard中选择它。
  2. 代码:

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

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

SKLabelNode(fontNamed: "Montserrat Light")

关于ios - 使用 Swift 3.0 将自定义字体添加到 SpriteKit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44100365/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com