Hi,
I'm just starting with NGUI but I've spent HOURS googling and reading forums looking for a simple answer to this question.
I have 4 dynamic buttons. I don't know how large (wide) the buttons need to be until run time.
I assign text to the label.
The label correctly sizes to the new text, the background does not.
How do I set the background to the new label width?
I have tried many things, including:
GameObject p = GameObject.Find("btnAnswer4");
UILabel l = p.GetComponentInChildren<UILabel>();
l.text = "Thsi is a longer button";
Vector2 size = l.font.CalculatePrintedSize(l.text, true, UIBaseFont.SymbolStyle.Colored);
Vector2 lwCharPixSize
= new Vector2
(size
.x * l
.transform.localScale.x, size
.y * l
.transform.localScale.y); UISlicedSprite bg = p.GetComponentInChildren<UISlicedSprite>();
bg.transform.localScale.Set(lwCharPixSize.x, lwCharPixSize.y, bg.transform.localScale.z);
NGUITools.AddWidgetCollider(p); //to update the collider to the new size