Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How to auto adjust font size to fit label

Discussion in 'UGUI & TextMesh Pro' started by Linus122xbb, Feb 17, 2015.

  1. Linus122xbb

    Linus122xbb

    Joined:
    Sep 20, 2014
    Posts:
    3
    Hello, I am having an issue where I sometmes have a very long text stored in a label component, which cannot be a multiline text, it has to be one a single line so the label has the horizontal overflow option set to overflow. This is not good because it will overflow onto my image next to the label thus it is very hard to read and looks really bad.

    I want to auto adjust the font size to fit in the actual label width no matter what. For instance if the label is 75 units wide containing the text "This is a very long text" I want the font size to be small enough to fit into the label. If the text is "Short" I want it to be a large font size.

    Thank you in advance!
     
  2. Simie

    Simie

    Joined:
    Oct 26, 2012
    Posts:
    454
    Enable "Best Fit" in the inspector of the Text component. That should enable the behaviour you are looking for.
     
    alicederyn likes this.
  3. Linus122xbb

    Linus122xbb

    Joined:
    Sep 20, 2014
    Posts:
    3
    Thanks this works well for a standalone label. But for some reason it doesn't do a thing if I try this with a toggle button, it just wraps to the next row, and the font size is the same. Any ideas?
     
  4. Linus122xbb

    Linus122xbb

    Joined:
    Sep 20, 2014
    Posts:
    3
    Nevermind I had the vertical overflow option set to overflow so it didn't work, so I set it to truncate and it works, however the text is smaller then when using a standalone label.
     
    alicederyn likes this.