- Home /
Anchor ui image to ui text
I have recently moved from NGUI to the new UI and I have a question.
I have a popup message with some interactions that I display when a user clicks on one of the game tiles. Now, not all tiles have the same number of interactions, so I would like the background of this message to grow/shrink vertically depending on the number of interactions displayed.
In NGUI this is pretty straightforward stuff but I don't seem to be able to reproduce this behaviour with the new UI.
Is this possible to achieve right now or would I have to calculate the length of the text myself and grow/shrink the background accordingly?
Thanks!
Answer by IvovdMarel · Feb 20, 2015 at 05:49 PM
uGUI works with a 'parent controls child' attitude, not the other way around. Therefore, the thing that you want (child controls parent) is a bit of extra work.
First, add a VerticalLayoutGroup or HorizontalLayoutGroup to your button, to place multiple items next to each other. Even if it's just one Text element, you should use this.
Now, add a ContentSizeFitter component to your button. It will shrink the button down to the preferred size of it's child (if you select that from the dropdown).
More info: http://docs.unity3d.com/Manual/HOWTO-UIFitContentSize.html
Thats exactly it! Thanks :)
I find that there is still a lack of information regarding many things in the new UI.
Your answer
Follow this Question
Related Questions
4.6.1 GUI. Get Pos Y property from script? 1 Answer
Infinite ScrollRect? 1 Answer
[4.6 GUI] Displaying my pause menu when ESC is pressed 2 Answers
Where do I find UI Text? 3 Answers
How do I keep an ui element in side of the canvas when scaling? 1 Answer