Although the docs claim that SceneKit's SCNText
works with NSAttributedString
, the following NSAttributedString
attributes seem to be ignored completely (and perhaps others, too):
shadow
strokeColor
strokeWidth
foregroundColor
SCNText
does obey NSAttributedString
's font
attribute, however -- and it does display on screen.
What I'm trying to do is add a stroke to my SCNText
. I do not want to use a SpriteKit overlay for such a simple use case.
From the docs:
When you create a text geometry from an attributed string, SceneKit styles the text according to the attributes in the string, and the properties of the SCNText object determine the default style for portions of the string that have no style attributes.
Here's what I'm doing in code. This code results in a white-filled text in the correct font, but without shadow or stroke of any kind:
let labelNode = SCNNode()
let label = SCNText(string: "\(targetLevel)", extrusionDepth: 0.0)
let font = UIFont(name: "Whatever", size: 4.0)
let shadow = NSShadow()
shadow.shadowBlurRadius = 1.0
shadow.shadowColor = UIColor.black
let attStr = NSAttributedString(string: "\(targetLevel)", attributes: [.font: font!, .shadow: shadow, .strokeColor: UIColor.black, .strokeWidth: 0.5])
label.string = attStr
label.alignmentMode = "kCAAlignmentCenter"
label.flatness = 0.01
//Using a big font and then scaling the node down to make it look less jagged:
labelNode.scale = SCNVector3(0.25,0.25,0.25)
labelNode.geometry = label
labelNode.castsShadow = false
parent.addChildNode(labelNode)
Questions: Am I doing something wrong -- or is this a limitation of SceneKit? Is there any other way to stroke an SCNText
? I saw this question, but it's about fill color, not stroke, and didn't fix my problem.