Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adjusting the height of Unity 4.6 UI Text according to content

Tags:

c#

text

unity3d

I am new to the unity's latest UI. What I know about UI Text Element is, we can wrap the text with in the horizontal bounds, but if it comes to next line, either it overflows or it truncates. If it fits in the height, font size decreases. What I want is to adjust the height of the text area according to the content it contains, without affecting the font size inside.

I will be having many text elements as childs to a parent panel, the panel itself will be child to a scrollable container. So I have to calculate height of all the children to adjust the height of the parent panel.

How do I achieve it?

like image 352
mdanishs Avatar asked Sep 03 '14 06:09

mdanishs


People also ask

How do you write text UI in unity?

To insert a Text UI element in Unity, right-click on the Scene Hierarchy, then select GameObject -> UI -> Text. There are many properties of the Text element. In which Text Field is the most important property. You can type out what you want the text box to show in that field.

How do I change font size in unity?

In unity, unfortunately, you can't increase the font size but as Dreamback told, you are always free to increase the size of text on display. First Select the Start button, Settings > Ease of Access > Display. To make text bigger screen larger, adjust the slider under Make text bigger.


1 Answers

Add a Content Size Fitter component to Text and set its Vertical Fit to PreferredSize.

I wrote a blog so people might find it helpful knowing how I used this component to create dynamic lists. http://mobile.folio3.com/creating-dynamic-scrollable-lists-with-new-unity-canvas-ui/

like image 126
mdanishs Avatar answered Sep 23 '22 06:09

mdanishs