Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started by: sintua 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.
-
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.
-
UIFont.CalculatePrintedSize. Don't forget to scale that value by the label's localScale.