Author Topic: Labels added to grid not repositioning  (Read 4270 times)

DuaneDog

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 27
    • View Profile
Labels added to grid not repositioning
« on: March 04, 2014, 10:38:09 PM »
Greetings,

I'm using the following code:

  1.  foreach (string CurrentValue in ShowList)
  2.         {
  3.             UILabel AddLabel = (UILabel)Instantiate(_uiLabel, transform.position, transform.rotation);
  4.             AddLabel.text = CurrentValue;
  5.             GameObject ItemAdded = NGUITools.AddChild(_uiGrid.gameObject, AddLabel);
  6.            
  7.         }
  8.         _uiGrid.Reposition();

The labels get added to the screen and are populated with the right text... but they are all bunched up. Should not the grid control getting called with reposition override the transforms on the label? I know I'm missing something simple... I think!

Thanks in advance,

DuaneDog

Prin_E

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: Labels added to grid not repositioning
« Reply #1 on: March 05, 2014, 02:24:04 AM »
Try this.

NGUITools.AddChild() automatically instantiates!

  1.  foreach (string CurrentValue in ShowList)
  2.         {
  3.             UILabel AddLabel = NGUITools.AddChild(_uiGrid.gameObject, _uiLabel.gameObject).GetComponent<UILabel>();
  4.             AddLabel.text = CurrentValue;
  5.         }
  6.         _uiGrid.Reposition();
  7.  

DuaneDog

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 27
    • View Profile
Re: Labels added to grid not repositioning
« Reply #2 on: March 05, 2014, 05:05:47 AM »
Many thanks that got them in the grid... My next problem is still related to repositioning. All my labels are center aligned in the scrollview. How can I get them to align left? I've tried messing with anchors and other options and I can't find a simple "align left" or way to easily make it work with the grid control. Am I going to be better off hand positioning and ditching the grid control altogether?

DuaneDog

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 27
    • View Profile
Re: Labels added to grid not repositioning
« Reply #3 on: March 05, 2014, 06:46:22 AM »
Update... I was able to get my labels left aligned with a pivot.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Labels added to grid not repositioning
« Reply #4 on: March 05, 2014, 07:39:32 AM »
Labels have the "Alignment" field you can set. No need to change the pivot.