Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 916
Jan F. Avatar asked Mar 19 '23 14:03

Jan F.


1 Answers

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.

like image 117
rickster Avatar answered Mar 29 '23 00:03

rickster