samir
samir

Reputation: 4551

UILabel Truncation

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?

Upvotes: 3

Views: 629

Answers (3)

Talha Ahmed
Talha Ahmed

Reputation: 158

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

Upvotes: 0

Derek Tomes
Derek Tomes

Reputation: 4007

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 

Upvotes: 4

Juan Boero
Juan Boero

Reputation: 6417

@DerekTomes answer in Swift 2.x:

label.adjustsFontSizeToFitWidth = false
label.lineBreakMode = .ByTruncatingMiddle

Upvotes: 0

Related Questions