1

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:

enter image description here

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.

Mina
  • 2,167
  • 2
  • 25
  • 32

1 Answers1

3

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...

BlackMirrorz
  • 7,217
  • 2
  • 20
  • 31
  • I’m using macOS 10.14 – Mina Aug 21 '18 at 16:12
  • These calculations with boundingBox is giving the exact size of the text? – Mina Aug 21 '18 at 16:13
  • The property is available when making an Xcode Project for MacOS. If you are making an IOS app then you cannot use the texSize property. – BlackMirrorz Aug 21 '18 at 16:15
  • Yes... https://developer.apple.com/documentation/scenekit/scnboundingvolume – BlackMirrorz Aug 21 '18 at 16:18
  • Thanks @Josh I solved the problem with your help and also answered a complete guide to how to cover a textNode with a PlaneNode [here](https://stackoverflow.com/a/51961959/1724845). – Mina Aug 22 '18 at 07:42