1

I am trying to create a simple input textfield which will expand vertically as the content outgrows the textfield size.

The textfield is set to multiline newline and vertical overflow. I have also added a Content Size Fitter script and set Vertical Fit to "Preferred Size"

When I enter text into the textfield, the preferred size never seems to change for the textfield. (My understanding is that preferred size should include the overflow).

It seems like a simple task, but I can't find a solution for this. Was wondering if anyone more experienced could show a quick example for this.

1 Answer 1

0

Place a "Content Size Fitter" component onto the GameObject with the Text component on it. Set the "Vertical Fit" parameter to "Preferred Size".

On the Text component set "Horizonal Overflow" to "Wrap" and "Vertical Overflow" to "Truncate".

That's it.

Now if you want a background to resize behind it as well then you may need to code it in but you can do that fairly simply by referencing the Text transforms' size.

Sign up to request clarification or add additional context in comments.

2 Comments

This works great when using just a text component. When we add an Input Field script or use an Input Field object setting "Line Type" to "MultiLine - Newline", the object refuses to resize.
Did you ever find a solution for this? I am also trying to get an InputField to resize the background image on multiline input

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.