I want to add a SCNPlane around the SCNText in ARSCNView. therefore I need the textSize of a text which I have created with SCNText like:
as you can see from the image, there is an error which indicate that the
SCNText has no member 'textSize'
but I can see the related documentation in apple website for both SCNText and textSize.
does anybody know what is the problem and how can I access the textSize property?
I'm using xCode 10.0 beta 4, swift 4.2, macOS Mojave 10.14 Beta.
The textSize
property is only available on macOS 10.8+
which is why you can't see it (assuming of course you are building for IOS). By this, I mean that if you are building a MacOS app then the variable is accessible. Whereas if you are building for IOS it is not.
If you want to get the size of your SCNText
you can use it's boundingBox
property to get its width and height for example e.g:
//1. Get The Bounding Box Of The Text Node
let boundingBox = textNode.boundingBox
//2. Get The Width & Height Of Our Node
let width = boundingBox.max.x - boundingBox.min.x
let height = boundingBox.max.y - boundingBox.min.y
If you just want to set the fontSize you can do something like so:
//1. Create An SCNNode With An SCNText Geometry
let textNode = SCNNode()
let textGeometry = SCNText(string: "StackOverflow", extrusionDepth: 1)
textGeometry.font = UIFont(name: "Skia-Regular_Black", size: 20)
Remembering of course that when you specify the font size in ARKit
, this in meters.
Hope it helps...