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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

uGUI - Resize TextField to match Text

Discussion in 'UGUI & TextMesh Pro' started by Hesel, Nov 11, 2014.

  1. Hesel

    Hesel

    Joined:
    Aug 4, 2014
    Posts:
    7
    In uGUI - How would I go about getting a Text component resized so it fits the amount of text in it?

    Is there a way to "ask" for the amount of pixels of a string, with a certain Font and FontSize?

    I'm not looking for the "Best Fit" checkmark solution. I have a Font, and a FontSize the string is supposed to be rendered with - I just want the Text component to resize itself as the text-string changes.


    /Andreas
     
  2. vatara

    vatara

    Joined:
    Feb 26, 2010
    Posts:
    22
    Add a Content Size Fitter to the GameObject
     
  3. Hesel

    Hesel

    Joined:
    Aug 4, 2014
    Posts:
    7
    Well, that was easy. I had no idea Preferred Size did that.

    Thank you.