1

I wanna resize of my textbox.My project getting some lines from firebase and ı dont know how many lines come for every data. for example here two text boxes. enter image description here

the top example: 2 lines come and text stuck. the bottom example: 1 lines come and text looking how i want . ı wanna every text same font size like second line. if 2 line comes text box resize but how?Maybe using TMP ?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
cantaş
  • 127
  • 1
  • 8

3 Answers3

0

instead of using unitys vanilla text module, I would use Textmesh Pro. Unity bought this Asset and made it free. Text looks a lot better with it.

As for your problem. You can either count the characters of your incoming string and do a switch-case so every x characters the text box increases to a new line. Or you need to loop over every character and add their width to get the string width and do some math with that number.

get text width / font character width

flyingchris
  • 316
  • 4
  • 10
0

I got all the texts inside the panel object and increased the panel object according to the length of the incoming text (my line length was around 30 characters). You can try.

dPanel.GetComponent<RectTransform>().sizeDelta = new Vector2(dPanel.GetComponent<RectTransform>().sizeDelta.x, 73 + (50 * PanelArttir(soru.dSikki.Length)));
            ePanel.GetComponent<RectTransform>().anchoredPosition = new Vector2(0, (dPanel.GetComponent<RectTransform>().anchoredPosition.y - 90 - (50 * PanelArttir(soru.dSikki.Length))));
cantaş
  • 127
  • 1
  • 8
0

You can adjust font like this

//some condition
gameObjectThatHasText.GetComponent<Text>().fontSize = 12;
vasmos
  • 2,472
  • 1
  • 10
  • 21