Jan F.
Jan F.

Reputation: 1691

SCNText Alignment not working in iOS

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!

Upvotes: 4

Views: 2576

Answers (1)

rickster
rickster

Reputation: 126107

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.

Upvotes: 7

Related Questions