See my screenshot. When the font size is 14, the height needs to be at least 19 to show one line of text. When the font size is 30, the height needs to be at least 41 to show one line of text. If I know text font size, is there a formula to get Text#minHeight?
-
[Unity Documentation - Making UI elements fit the size of their content](https://docs.unity3d.com/Manual/HOWTO-UIFitContentSize.html) – Flater Sep 20 '18 at 13:44
3 Answers
One of the following solutions should solve your problem:
Option 1: Make the text always visible regardless of its size
In the inspector, set the Vertical Overflow
property to Overflow
so that the text will always show even if it does not fit within the vertical constraints of the box.
Option 2: Make the text auto size itself to fit the space
In the inspector, check the "Best Fit" checkbox and enter the minimum and maximum sizes you would like your text to be. The text will then size itself so it is as large as possible without overflowing.

- 6,196
- 7
- 23
- 39
This is probably due to how fonts are designed
In this case, we're interested in the difference between the purple and green lines plus the difference between the blue and orange. A font's "size" is the height between the green and blue lines (roughly speaking). Some fonts may have been designed to be taller or shorter than this standard, but how a system renders them will be based on the standard (and may not render correctly as a result). This is why some fonts at the same size look smaller.
Along with some numbers from this answer, your own post, and some additional ones by messing around in Unity...
Your text height needs to be Math.Ceil(font_size * 1.35)
in size...but that multiplier depends on the specific font you're using! Unity's default Arial font has a multiplier of 12% (1.12) and another font I had in my assets folder needed 25%.
The easiest way to find this multiplier is to set the font size to 100 and then find the height needed for it to display. Then knowing that ratio, you'll be able to correctly calculate the height needed for a given font size.

- 1
- 1

- 15,628
- 3
- 36
- 56
I find tmp solution, If i need make sure Text show at lease one line, I can set
Horizontal Overflow: Overflow
Vertical Overflow: Overflow
it will always show text, but maybe show multi lines, so if I wanna only show one line, i need other way

- 3,591
- 4
- 41
- 73