问题
I tried right alignment, but it's still left aligned.
let txt = SCNText(string: "TEST", extrusionDepth: 10)
txt.chamferRadius = 5 //0<chamfer<extrusion depth
txt.firstMaterial.diffuse.contents = UIColor.whiteColor()
txt.containerFrame = CGRectMake(-200, -150, 400, 200) //on iPad Air Sim in Landscape
txt.wrapped = true
txt.alignmentMode = kCAAlignmentRight
What is wrong?
Thanks!
回答1:
It looks like alignment is working -- try adding a second line to your test string like "TEST\nT"
and switching between left and right alignment modes. But SCNText
adapts to fit the coordinate system of its node, so alignment alone won't necessarily make the text fit into your scene the way you want it to.
You can tweak how a node's content fits into its parent space using the node's pivot
property. Set it to a translation transform (SCNMatrix4MakeTranslation
) based on the bounding box of your text and you can change the layout however you like.
来源:https://stackoverflow.com/questions/25652946/scntext-alignment-not-working-in-ios