小编Ant*_*sov的帖子

SKLabelNode + NSMutableAttributedString = 无阴影

    let paragraph = NSMutableParagraphStyle()
    paragraph.alignment = NSTextAlignment.right
    paragraph.tailIndent = -3
    let shadow = NSShadow()
    shadow.shadowBlurRadius = 5
    shadow.shadowColor = UIColor.gray
    shadow.shadowOffset = CGSize(width: 2, height: -2)
    let text = NSMutableAttributedString(string: "MY LABEL", attributes:
   [NSShadowAttributeName : shadow,
    NSStrokeColorAttributeName : UIColor.black,
    NSStrokeWidthAttributeName : -3,
    NSForegroundColorAttributeName: UIColor.white,
    NSFontAttributeName : UIFont(name: "MyFont", size: 24) as Any,
    NSParagraphStyleAttributeName : paragraph])

    let node = SKLabelNode()
    addChild(node)
    node.attributedText = attributedString
Run Code Online (Sandbox Code Playgroud)

它有效,但没有阴影。我可以使用相同的NSMutableAttributedString上著名的ASAttributedLabel和它的作品不错,有一个影子,但我想使用SKLabelNode,以实现更好的性能IOS11ASAttributedLabel可能会滞后于动态场景:(

nsattributedstring nsmutableattributedstring sprite-kit sklabelnode swift

6
推荐指数
0
解决办法
375
查看次数