Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: ThomasIndustry on August 12, 2015, 04:06:40 PM

Title: [Solved]Updating Dynamic Label's Width Immediatly
Post by: ThomasIndustry 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);
Title: Re: Updating Dynamic Label's Width Immediatly
Post by: ThomasIndustry on August 13, 2015, 10:30:58 AM
I figured it out:

  1. theLabel.CalculateBounds()