Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started by: Paul on October 16, 2015, 07:16:41 PM
-
I'm trying to anchor a sprite to the left side of the longest of two dynamic text strings.
(http://i.imgur.com/9HWv91U.png)
I do this by calling SetAnchor(longestLabel) in code, however the sprite's position shifts at runtime when anchored to the top label. I believe this is because the Left, Right, Bottom & Top offsets are not being updated at runtime when SetAnchor() is called.
However the L, R, T & B offsets DO update automatically in the editor when dragging a new Target onto the anchor property. How do I replicate that behavior at runtime?
Or is there an easier way to accomplish what I'm trying to achieve?
-
In the interest of time, I decided to use the max myLabel.width property to position the sprite, but I would still like to know if this is possible with anchors.
-
Yes, it's possible by doing this:
Widget (use it for positioning the content)
- Empty game object
-- Label 1
-- Label 2
- Widget A (another invisible widget) with UIEnvelopContent on it targeting the Empty game object
- Sprite anchored to the Widget's left side
You can also just make the Widget A's pivot be top-left instead of center, then the sprite can simply be its child positioned where you need it to be. You can skip anchoring it then.
-
Fantastic, thanks ArenMook!! UIEnvelopContent was the missing piece of the puzzle. =)