swift - 有什么方法可以为 iOS 10 及更高版本将字距设置为 SKLabelNode?
问题描述
我想将字距设置为SKLabelNode
. 我使用NSAttributedString
了这个解决方案,并且在 iOS 11 或更高版本上运行良好。
但我也需要支持 iOS 10。有没有办法设置支持 iOS 10 及更高版本的字距调整?
class Caption: SKLabelNode {
static func addNode(at position: CGPoint, isBold: Bool, text: String) -> Caption {
let font = isBold ? "Roboto-Bold" : "Roboto-Regular"
let attr: [NSAttributedString.Key: Any] = [
.font: UIFont(name: font, size: 16)!,
.foregroundColor: SKColor.white,
.kern: 2.0
]
let caption = Caption(attributedText: NSAttributedString(string: text.uppercased(), attributes: attr))
caption.horizontalAlignmentMode = .center
caption.verticalAlignmentMode = .top
caption.position = position
return caption
}
}
Xcode 说:'init(attributedText:)' is only available on iOS 11 or newer.
let caption = Caption(attributedText: NSAttributedString(string: text.uppercased(), attributes: attr))
解决方案
答案是不。您将不得不想出一种不同的方法,例如使用 UILabel 渲染,从中提取 UIImage,在 SKSpriteNode 上使用 UIImage。
当然,最简单的解决方案就是放弃对 iOS 10 的支持(大约 5% 的 iOS 用户使用 iOS 10)
推荐阅读
- apache-spark - Calcite JDBC-Spark 集成
- microservices - 审核多个微服务中各种用户操作的日志记录
- rest - 对于有助于决策的 REST 端点来说,什么是一个好的实践
- python - 我们如何从 Python 执行以下命令提示符脚本
- html - 如何将 d3 可缩放旭日形图中的最后一个节点作为超链接?
- android - 在运行时创建的按钮如何在每个 clicklistener 上设置?
- postgresql - 如何修复 org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; 糟糕的 SQL 语法
- android - 在 ubuntu 中运行本机应用程序时出错
- python - 使用 .apply() 清理数据框中的电子邮件 - 数据框未更新
- python - get_tk_widget() 框架周围的边框