Author Topic: [Solved]Updating Dynamic Label's Width Immediatly  (Read 1521 times)

ThomasIndustry

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
[Solved]Updating Dynamic Label's Width Immediatly
« on: August 12, 2015, 04:06:40 PM »
I am trying to dynamically create dynamic buttons by adding text to a label that is set to Resize freely, and then adding a box collider, but I cannot find a way to do this in the same frame. How can I force the label to recalculate its width immediately before creating the collider? I have tried MarkAsChanged and SetDirty, but they are not updating the width field.

  1. theLabel.overflowMethod = UILabel.Overflow.ResizeFreely;
  2. theLabel.text = theCategory;
  3.  
  4. theCollider = this.gameObject.AddComponent<BoxCollider>();
  5. theCollider.size = new Vector3(theLabel.width + 100, theLabel.height, 1f);
« Last Edit: August 13, 2015, 03:52:12 PM by ThomasIndustry »

ThomasIndustry

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: Updating Dynamic Label's Width Immediatly
« Reply #1 on: August 13, 2015, 10:30:58 AM »
I figured it out:

  1. theLabel.CalculateBounds()