gpt4 book ai didi

ios - 旧金山字体 + SpriteKit

转载 作者:行者123 更新时间:2023-11-29 01:36:56 25 4
gpt4 key购买 nike

目前可以在 SpriteKit 的 SKLabelNode 中使用 iOS 9 的新 San Francisco 字体吗? Apple 明确要求我们不要按名称实例化字体,但这是 SKLabelNode 提供的选择字体的唯一方法。

最佳答案

通过UIFont的属性fontName获取系统字体名称:

let myLabel = SKLabelNode(fontNamed:UIFont.systemFontOfSize(45.0).fontName)

字体名称的打印结果:

.SFUIDisplay-Regular

编辑:

WWDC 2015 Video: Introducing the New System Fonts方面,PDF 的第 298 页说不要按名称访问系统字体,例如

let myFont = UIFont.systemFontOfSize(mySize)
// …later in the code…
let myOtherFont = UIFont.fontWithName(myFont.familyName size:mySize)

更好的做法(第 299 页)是重复使用字体描述符,例如

let systemFont = UIFont.systemFontOfSize(mySize)
// …later in the code…
let myOtherFont = UIFont.fontWithDescriptor(systemFont.fontDescriptor()
size:mySize)

请注意代码描述了一种情况,您需要访问之前定义的字体 (myFont)。为了保持应用程序中字体的一致性,您最好使用已经定义的fontDescriptor,而不是在未设置其属性的情况下访问完整的字体。不要混淆。

关于ios - 旧金山字体 + SpriteKit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32859132/

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