在Swift中给SKLabelNode加下划线,可以通过以下步骤实现:
let labelNode = SKLabelNode(text: "Hello World")
labelNode.fontName = "Helvetica"
labelNode.fontSize = 20
labelNode.fontColor = UIColor.white
let underlineNode = SKShapeNode(rectOf: CGSize(width: labelNode.frame.width, height: 1))
underlineNode.fillColor = UIColor.white
underlineNode.position = CGPoint(x: labelNode.position.x, y: labelNode.position.y - labelNode.frame.height/2)
labelNode.parent?.addChild(underlineNode)
完整的代码示例:
import SpriteKit
class GameScene: SKScene {
override func didMove(to view: SKView) {
let labelNode = SKLabelNode(text: "Hello World")
labelNode.fontName = "Helvetica"
labelNode.fontSize = 20
labelNode.fontColor = UIColor.white
addChild(labelNode)
let underlineNode = SKShapeNode(rectOf: CGSize(width: labelNode.frame.width, height: 1))
underlineNode.fillColor = UIColor.white
underlineNode.position = CGPoint(x: labelNode.position.x, y: labelNode.position.y - labelNode.frame.height/2)
labelNode.parent?.addChild(underlineNode)
}
}
这样就可以在Swift中给SKLabelNode加下划线了。
领取专属 10元无门槛券
手把手带您无忧上云