3

How would you get the intrinsicContentSize like for a UILabel but for an SKLabelNode?

My not-so-educated-guess would be to create a UILabel with the same font and just get its' intrinsicContentSize... but this seems sloppy.

twodayslate
  • 2,803
  • 3
  • 27
  • 43
  • In short, you should implement something like that by yourself. See if this helps in some way : http://stackoverflow.com/a/32185228/3402095 SKLabelNode is not the same with UILabel, it is not even similar. It is very basic element actually with limited possibilities (in compare to UILabel). – Whirlwind Dec 24 '16 at 09:21
  • Are you looking to find the width of an SKLabelNode of a given string at a given size of a given font? – Confused Dec 24 '16 at 10:00
  • @Confused I would say he wants to resize label's width to automatically fit its content. – Whirlwind Dec 24 '16 at 12:39
  • @Confused is correct, I am looking for the width of the label – twodayslate Dec 24 '16 at 16:28
  • The size of a label node is determined implicitly by the label node’s fontName, fontSize, and text properties. That is from the docs. To get the label's width, just set text and print label.frame.size.width property. – Whirlwind Dec 25 '16 at 00:42
  • Can you expand on how to actually do that (calculate width) @Whirlwind? – twodayslate Dec 25 '16 at 19:30
  • I explained above. just read the frame property (frame.size.width) – Whirlwind Dec 25 '16 at 21:09
  • @Whirlwind the frame doesn't necessarily represent the size of the text tho – twodayslate Dec 25 '16 at 21:13
  • I meant label.frame. frame.size property is based on text directly. You should update your question with a minimal example which can reproduce the issue. – Whirlwind Dec 25 '16 at 21:16
  • Also there is calculateAccumulatedFrame() method which returns the biggest rectangle that contains the content of the node and all of its descendants. – Whirlwind Dec 25 '16 at 21:20
  • @Whirlwind awesome. you're right. you can post that and I'll accept the answer – twodayslate Dec 26 '16 at 01:20

0 Answers0