- Home /
[4.6] Auto grow/shrink a panel to fit its contents
Hi there,
I'm trying to create a UI panel that automatically grows and shrinks based on its contents. (which are dynamic) Right now I have a panel set up with a vertical layout group in order to fit the Text objects inside of it, but I would like to have the main panel expand as it gets more text fields.
Is there a component for this or do I have to do it by code?
Answer by Kiwasi · Dec 18, 2014 at 10:12 AM
Are you after the ContentSizeFitter?
Check out this tutorial. There is a follow up tutorial linked at the end of the video that shows how to do it via script.
Thank you this was indeed what I was looking for. Had to tweak it as my object structure is a bit more complex but it did work.
Answer by Mmmpies · Dec 18, 2014 at 09:08 AM
try this, it's not perfect as resolution changes need fixing but it works fine if you have a set resolution.
Your answer
![](https://koobas.hobune.stream/wayback/20220613174330im_/https://answers.unity.com/themes/thub/images/avi.jpg)