SCNText Alignment not working in iOS

随声附和 提交于 2021-02-07 07:19:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!