UILabel Truncation
-
29-10-2019 - |
Frage
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?
Lösung
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
Andere Tipps
@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
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow