Author Topic: Add new labels to scrollable view at runtime  (Read 4588 times)

gamedivisionuk

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 36
    • View Profile
Add new labels to scrollable view at runtime
« on: May 18, 2014, 05:09:43 PM »
i have an app that has one line of text per item when i click save i need to be able to save that to a scrollable view using a label,each time i create a new item i need to add it to that scrollable view could be around 150 items that need adding to that scrollable view
im using playmaker at the moment when adding another label at runtime it creates it on top of the previous, anyway of the labels being able to reposition themselves within the scrollable view

thank you

rahares

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Add new labels to scrollable view at runtime
« Reply #1 on: May 18, 2014, 05:21:39 PM »
I use this to create the objects on scrollview grid ....Should be able to create your label as a prefab and do the same

GameObject addnewitem = NGUITools.AddChild(YOURGRID.gameObject, YOURLABELPREFAB); // creates a new Grid Item
            UILabel[] labels = addnewItem.GetComponentsInChildren<UILabel>();
            foreach (UILabel label in labels) { // Checks each label and assigns the values
               switch (label.name)   {
               case "MYLABELNAME":
                  label.text = STUFFTOADD;
               break;

then call YOURGRID.Reposition();

i have multiple labels and not just one so theres probally a better way for that then using a switch but the basic idea is the same i would think

gamedivisionuk

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 36
    • View Profile
Re: Add new labels to scrollable view at runtime
« Reply #2 on: May 19, 2014, 05:35:17 AM »
thanks for that i am using a prefab but its the relocation it creates it on top of the original

I use this to create the objects on scrollview grid ....Should be able to create your label as a prefab and do the same

GameObject addnewitem = NGUITools.AddChild(YOURGRID.gameObject, YOURLABELPREFAB); // creates a new Grid Item
            UILabel[] labels = addnewItem.GetComponentsInChildren<UILabel>();
            foreach (UILabel label in labels) { // Checks each label and assigns the values
               switch (label.name)   {
               case "MYLABELNAME":
                  label.text = STUFFTOADD;
               break;

then call YOURGRID.Reposition();

i have multiple labels and not just one so theres probally a better way for that then using a switch but the basic idea is the same i would think