将背景添加到SKLabelNode

时间:2017-08-26 18:30:56

标签: ios swift sprite-kit sklabelnode

我一直在尝试在我的SKLabelNode周围添加一个背景,但我无法弄清楚如何在swift 3中以编程方式进行。我看到一些使用.background的旧帖子,但这对我不起作用。

let background = SKSpriteNode(color: UIColor.white, size: CGSize(width: CGFloat((title.frame.size.width)), height:CGFloat((title.frame.size.height)))) 
background.zPosition = -1
background.position = CGPoint(x: self.frame.width / 12 * 6, y: self.frame.height / 12 * 11); title.addChild(background)

1 个答案:

答案 0 :(得分:2)

检查这个新代码,我认为这更适合您的问题

    let shape = SKShapeNode()
    shape.path = UIBezierPath(roundedRect: CGRect(x:(label?.frame.origin.x)! - 15, y: (label?.frame.origin.y)! - 15, width: ((label?.frame.size.width)!+30), height: ((label?.frame.size.height)! + 50 )), cornerRadius: 64).cgPath
    shape.position = CGPoint(x: frame.midX, y: frame.midY)
    shape.fillColor = UIColor.red
    shape.strokeColor = UIColor.blue
    shape.lineWidth = 5
    label?.addChild(shape)

Layout