Question

I have text like this: "My text is blabla blabla, lala lala ".

I would like to have the text in my UILabel like this: "My text is ...lala".

How can I configure my UILabel to display the text to have the ellipsis in the middle?

Was it helpful?

Solution

The word you are looking for is "ellipsis" ;)

Set the following properties:

label.adjustsFontSizeToFitWidth = false;
label.lineBreakMode = .byTruncatingMiddle;

You can also set these properties in interface builder.

Example stolen from here: Getting UILabel to produce an ellipsis rather than shrinking the font

UPDATE:

This was deprecated in iOS 6. The current solution would be the slightly modified:

label.adjustsFontSizeToFitWidth = NO;
label.lineBreakMode = NSLineBreakByTruncatingMiddle 

OTHER TIPS

@DerekTomes answer in Swift 2.x:

label.adjustsFontSizeToFitWidth = false
label.lineBreakMode = .ByTruncatingMiddle

Try to select the label, then in attribute inspector set line break to truncate middle image reference

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top