Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: dwjkim on August 30, 2013, 01:42:31 AM

Title: How do I resize Labels that are instantiated run-time?
Post by: dwjkim on August 30, 2013, 01:42:31 AM
I coded to resize the label size but obviously the font size is read-only.

               subject[idx] = NGUITools.AddChild(mPanel, mLabelPrefab);      
               label = subject[idx].GetComponent<UILabel>();
               label.font.size = 14;

When the labels are instantiated, they are automatically set at 1, 1, 1.

What can I do?
Title: Re: How do I resize Labels that are instantiated run-time?
Post by: dkozlovtsev on August 30, 2013, 01:47:09 AM
i can be wrong, but UILabel is derived from UIWindget which is derivative of MonoBehavior, so it is safe to assume that you can use label.transform
Title: Re: How do I resize Labels that are instantiated run-time?
Post by: dwjkim on August 30, 2013, 02:49:42 AM
               subject[idx] = NGUITools.AddChild(mPanel, mLabelPrefab);      
               label = subject[idx].GetComponent<UILabel>();
            Vector3 scale = new Vector3(14f, 14f, 14f);
               label.transform.localScale.Scale(scale);

Tried this code and nothing changes. Any other ideas?
Title: Re: How do I resize Labels that are instantiated run-time?
Post by: dkozlovtsev on August 30, 2013, 03:25:27 AM
Weird, it works for me. try calling MarkAsChanged() on it
Title: Re: How do I resize Labels that are instantiated run-time?
Post by: dwjkim on August 30, 2013, 04:51:57 AM
               label = subject[idx].GetComponentInChildren<UILabel>();
               subject[idx].AddComponent<UIButtonMessage>();
               msg = subject[idx].GetComponent<UIButtonMessage>();
               msg.target = gameObject;
               
               msg.functionName = "ClickSubject";
               msg.trigger = UIButtonMessage.Trigger.OnClick;
            label.text = scn;         
            subject[idx].AddComponent<Task>();
            Task task = subject[idx].GetComponent<Task>();
            task.tasklevel = level;
            task.taskid = idx;
            Vector3 scale = new Vector3(2f, 2f, 0);
            subject[idx].GetComponent<Transform>().localScale.Scale (scale);


I have no idea what that MarkedAsChanged is.

I tried this code and it still does not work. I tried using button instead of label and it does not get resized.

Would it be because the panel is a UI Table? I think I tried around that but I do not think it is because the panel is UI Table.

buttons are clones of a single prefab.

Title: Re: How do I resize Labels that are instantiated run-time?
Post by: ArenMook on August 30, 2013, 05:01:16 PM
label.transform.localScale = new Vector3(300f, 200f, 1f);