How to make UILabel text appear with "..." at the end when the text is longer than the label width

My problem is with UILabel .

The text it holds is much longer than the actual width of the UILabel. Therefore, I would like it to appear with a “...” at the end to indicate that there is more text.

I played with the priority of horizontal crawl (made it less than 251), but it doesn't seem to matter.

Now it just interrupts the text when the width is filled.

Any ideas?

+5
source share
2 answers

This is pretty easy!

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

2) Create an IBOutlet.

3) Do:

 aLabel.adjustsFontSizeToFitWidth = false aLabel.lineBreakMode = .ByTruncatingTail 
+5
source

If you add UIlabel through a Storyboard, the following steps may be useful:

1) Select a shortcut which you want to display "..." at the end.

2) Go to the attribute inspector .

3) Select " Line Breaks " and select the Truncate Tail option

4) Check this by providing text with a larger content size than the label size.

0
source

All Articles