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

ellipsis for text overflow?

Discussion in 'UGUI & TextMesh Pro' started by tyoc213, Jan 26, 2016.

  1. tyoc213

    tyoc213

    Joined:
    Nov 14, 2011
    Posts:
    168
    Hi there, I need to put some text but if the text overflow I need to show "..." and basically the thing is that it should work on iOS, android, BB and Windows phone devices, and also support landscape and portrait.

    I can't seem to find how to do it? any help is greatly appreciated.
     
  2. DWilliams

    DWilliams

    Joined:
    Jan 12, 2015
    Posts:
    63
    There's nothing built into the UI system to do this that I'm aware of but a UI Text component has a TextGenerator object called cachedTextGenerator which has two int values, characterCount and characterCountVisible that you can compare to find out if the text string is being truncated. From that you should be able to make something. Just be aware that characterCount is always at least 1 more than characterCountVisible, even if all characters are showing. (characterCount doesn't seem to ever go below 1).
     
  3. Stephan-B

    Stephan-B

    Unity Technologies

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    In the event you don't have time to implement your own solution to support Ellipsis, you can take a look at TextMesh Pro which includes an Ellipsis text overflow mode.

    This feature has been in TextMesh Pro for several releases. In the next release this will also work with the new Multi Fonts & Sprites as well as font Fallback support as seen below.


    Text object shown uses 3 different fonts and a sprite. Click to see full size.

    TextMesh Pro is a replacement for Unity's text components providing added functionality in terms of text formatting, layout and rendering. There are two text components to choose from. One replaces the UI Text component supporting the Canvas system and layout system. The other is a replacement for the older Text Mesh component.
     
    Last edited: Jan 27, 2016
  4. Omid7L

    Omid7L

    Joined:
    Jun 10, 2018
    Posts:
    14