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

Unity UI Text size based on resolution/ppi

Discussion in 'UGUI & TextMesh Pro' started by ireth_86, Sep 20, 2018.

  1. ireth_86

    ireth_86

    Joined:
    May 18, 2016
    Posts:
    23
    Hello everybody,
    I'm writing some code that will run on both iOS and Android smartphones and tablets. I'm having issues understanding how to handle text.

    I have a screen canvas (Scale with Screen Size). All my boxes are anchored around the canvas in order to resize on different resolutions. All my texts components have Auto Size checked, and I've set a maximum size of 95. I can't know in advance how the text will look because I load it all from files during runtime.

    My problem is that if I test the code on an iPhone SE (1136x640, 326ppi) the readability of the text is good enough, but on an iPad Air (2048x1536, 264ppi) it's way too big.
    I figured that maybe I should set the maximum size of texts during runtime, based on the ppi maybe, I just can't figure out how. I thought that Scale with Screen Size would have been enough to make it work.

    Thanks in advance for any help.
     
  2. ireth_86

    ireth_86

    Joined:
    May 18, 2016
    Posts:
    23
    Anyone?

    I'm running some tests, and apparently the number of dpi is relevant until a certain point.
    I set a "base level" of text size, let's say my title has size 90 for a 326 dpi device, and when I launch the application I compute a factor (Screen.dpi / base_level_dpi) and multiply it for the text size. It works fine on iPad (lower dpi), but the text size increases too much on devices with a higher number of dpi (640 dpi, Samsung S7). Apparently, the readability is still good without this trick on the S7.

    So, it makes sense with device with lower dpi value, but not with higher. What am I missing?
    Thanks again.