How to make UILabel text appear with ellipsis at the end when text is longer than label's width

10,949

It is fairly easy:

  1. Create a UILabel called "aLabel" for example.

  2. Create an IBOutlet.

  3. Do:

    aLabel.adjustsFontSizeToFitWidth = false
    aLabel.lineBreakMode = .byTruncatingTail
    
Share:
10,949
ppp
Author by

ppp

Updated on June 08, 2022

Comments

  • ppp
    ppp almost 2 years

    My issue is with a UILabel.

    The text it holds is much longer than the actual width of the UILabel. So I would like it to appear with "..." (an ellipsis) at the end to denote that there's more text.

    I played around with horizontal content hugging priority (made it less than 251) but it doesn't seem to make a difference.

    Right now it just chops the text when the width fills up.

  • ppp
    ppp almost 8 years
    thanks for your reply. I tried it but no effect. Still chops the text without an eclipse at the end. Could it be that I added a width auto-layout constraint to the UILabel?
  • Coder1000
    Coder1000 almost 8 years
    @Polis This is extremely weird. When I create a UILabel and give it constraints, an ellipsis automatically appears if the text is too long. And I did add a width constraint. Please try recreating your UILabel :)