Author Topic: UILabel side by side, automatically adjust offsets as needed  (Read 2625 times)

antininja

  • Guest
I'm trying to place two UILabels side by side -- specifically, a score label next to the word "score" -- but I can't figure out how to do it with NGUI's scripts. I found an old post that suggests that there's a way to use UIAnchor to attach one object to the side of another, and then update the object's boundaries:

http://www.tasharen.com/forum/index.php?topic=1367.0

but I couldn't figure out how to implement it properly. There's no option in the current version of UIAnchor allowing you to attach an object to another, and while you can set one label as the widget-container of the other, the boundaries of the second label does not get updated when the text is changed. Is that post out of date?

I found another post that suggests that UITable might be the solution:

http://www.tasharen.com/forum/index.php?topic=1279.0

The post says that the cell sizes will be automatically adjusted to fit their content, but that only seems to happen once, when you click reposition now. Same question, out of date?

I checked some of the example scenes but couldn't find anything that addressed this question.

antininja

  • Guest
Re: UILabel side by side, automatically adjust offsets as needed
« Reply #1 on: June 17, 2013, 03:10:02 PM »
I think I figured it out. I'll leave this thread up for search engine bait. I'm still curious about the UIAnchor "attach one object to the side of another" feature, though.

In NGUI, alignment is set using the pivot option that appears in the inspector. So, if you want label A to sit next to label B, and label B will be changing in size (say it's the player score), create the two labels, set the pivot of label B to "left" (click on the left arrow in the inspector just above "Depth") and then place the labels where you want them to be. You should be able to modify the text in label B and see that it remains next to label A.