Author Topic: Setting UILabel.text doesn't compute the size instantly  (Read 3549 times)

Erhune

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 13
    • View Profile
Setting UILabel.text doesn't compute the size instantly
« on: January 22, 2014, 01:50:09 PM »
Between 3.0.0 and 3.0.6, it used to be that setting a UILabel.text would compute the UILabel.width and UILabel.height right now. I used this all the time to compute my layout in many parts of my GUI. Now, I have to do that in a coroutine: set the text, yield until the next frame when the width and height will be computed, and reposition everything. Of course, that means I have a 1-frame flicker which I didn't have before.

I understand this computation must be delayed for performance reasons, but isn't there a way to force it? Something like UILabel.ComputeSizeNow()...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Setting UILabel.text doesn't compute the size instantly
« Reply #1 on: January 23, 2014, 06:43:59 AM »
You can do immediately like so:
  1. UILabel lbl = GetComponent<UILabel>();
  2. lbl.UpdateNGUIText();
  3. NGUIText.CalculatePrintedSize(...);