- Home /
UI 4.6 : Anchor to dynamic text ?
Hi everyone.
I'm trying to anchor a UI component in 4.6 to the END of a text. I can anchor it but into the text square (right, bottom, top, left), but of course it doesn't move when the text change, cause the square never resize.
So how can I anchor a UI Component to the end of a text ?
IF NOT, may be you can help me find another solution : i'm trying to display a text like this : "Laboratory level 10". The "Laboratory" part has a big font size, and the "level 10" has a small font size. So I can't put them into the same Text component if I want two different font size, right ? That's why i'm trying to anchor "level 10" to the end of "Laboratory".
Did some one got an idea to achieve this ?
Thanks a lot.
Answer by Mmmpies · Feb 05, 2015 at 05:08 PM
Can't you just set Align in the Laboratory to right?
So the end of the, presumably room name, is always next to the level number.
EDIT
Thought you probably had too much Karma to not thought of that but you never know.
Try adding Content Size filter and set Horizontal to Preferred Size and it should re-size the RectTransform of the Text to fit the text inside it. Set the pivot to the middle left so it always grow out to the right.
Nope, the "Laboratory" part needs to be align to the left in my UI, so this trick can't work :)
But thanks !
EDIT : Never know of Content Size Fitter, it was exactly what I looking for ! I'm pretty new with 4.6, I used NGUI before, so that's why I'm asking maybe "obvious" question. And Google didn't help much this time.
Thanks !
That's O$$anonymous$$ @Benou$$anonymous$$at and thumbs up for taking the time to come back and change the answer. Pivots are also really important for the new UI, they can drastically change the way panels react to size or content changes.
Get on YouTube and check out Richard Gubb's Unity videos, he does a lot of clever stuff with the new UI.
Your answer
![](https://koobas.hobune.stream/wayback/20220613182556im_/https://answers.unity.com/themes/thub/images/avi.jpg)