Regarding the text box adaptation problem of TextMeshPro (UI) - personal rookie notes

1. Regarding the issue of automatic line wrapping of text

You can change the Wrapping option  in the component to Disable


 

2. Regarding the problem of the text box size adapting to the text length

We need to add a parent object to the text, add a Content Size Fitter component to the parent object and the text object, and add a Vertical Layout Group or Horizontal Layout Group component to the parent object (here you only need to check the full Child Force Expand, the purpose is In order to adapt to the size of sub-objects)

        When the Wrapping option is Enable (height adaptive): Set the Vertical Fit of both Content Size Fitter components to Preferred Size.

         When the Wrapping option is Disable (width adaptive. Because there is component control, it is also possible to use Enable): Set the Horizontal Fit of both Content Size Fitter components to Preferred Size.

        ps: If Preferred Size is selected under the Content Size Fitter component, the width will be adaptive.

        If you want the content to appear vertically . The Wrapping option is Ensable, all Preferred Sizes are selected under the Content Size Fitter component of the parent object , the width of the text object is changed to 1, and the Vertical Fit of its Content Size Fitter component is Preferred Size.


 There may be many loopholes in the notes. You are welcome to point them out and I will correct them as soon as possible. Thank you! ! !

Guess you like

Origin blog.csdn.net/WinDivI/article/details/133378425