Author Topic: Finding the length(x) of a label?  (Read 5956 times)

sintua

  • Jr. Member
  • **
  • Thank You
  • -Given: 7
  • -Receive: 0
  • Posts: 63
    • View Profile
Finding the length(x) of a label?
« on: March 17, 2013, 02:55:28 PM »
I don't know if anyone has come across this issue, but: I would like to find the length of a label. Given that label's "scale" is used for something other than the actual width, is there a way to pull this off? I'm sure I could do some math on the length of the string but that wouldn't account for the non-monospace font.

Specifically, I'm trying to create a "ticker" sort of effect like SimCity with various-length headlines scrolling along the bottom, with windows sized to hold the headline, starting just after the previous one finished and continuing in a scroll. I'll need the label length to size the text window, and to connect them in one continual string.

Buey

  • Guest
Re: Finding the length(x) of a label?
« Reply #1 on: March 17, 2013, 03:58:38 PM »
You could try to use a UITable to automatically position the elements.  I'm not sure if it accounts for the string length in a label, but it's worth a shot.

[edit]

It looks like UITable does work.  If you still want to do it manually, you could look at UITable's source to see how it's accounting for the string length.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Finding the length(x) of a label?
« Reply #2 on: March 17, 2013, 04:08:53 PM »
UIFont.CalculatePrintedSize. Don't forget to scale that value by the label's localScale.