I'm looking for a possibility to calculate the size of an SCNText Geometry. I want to make a row of individual text nodes that have a frame around the text.
Let's say the text has 5pt width. I want a SCNPlane as background with a width of 7pt and the text centred inside. How can I calculate the text size dynamically? I tried different things.. Monospace Fonts, counting bigger and smaller chars etc. But it didn't work out.
Like this:
---------- ----------
| Text | | Text |
---------- ----------
Here some sample code:
let textGeometry = SCNText(string: name, extrusionDepth: 0.1)
textGeometry.font = UIFont(name: "Helvetica Neue", size: 1)
let textNode = SCNNode(geometry: textGeometry);
Thanks
SCNNode
and SCNGeometry
(and thus SCNText
) conform to the SCNBoundingVolume
protocol. The method your are looking for is -getBoundingBoxMin:max:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With