-1

I want UIlabel to truncate text and present ... at the end. Is there an automatic way to do that?
(I was under the impression that it happens automatically like in UIButton but it doesn't)

Boaz
  • 4,864
  • 12
  • 50
  • 90
  • Reading [the docs](https://developer.apple.com/library/ios/documentation/uikit/reference/UILabel_Class/Reference/UILabel.html#//apple_ref/occ/instp/UILabel/lineBreakMode): *NSLineBreakByTruncatingTail The line is displayed so that the beginning fits in the container and the missing text at the end of the line is indicated by an ellipsis glyph.* Don't be lazy. – duci9y Jul 27 '14 at 10:53
  • @duci9y - today I learnt a new word ellipsis (non native english speaker... sorry... :)) – Boaz Jul 27 '14 at 11:39

1 Answers1

0

It happens automatically if lineBreakMode is set properly and the text contained by your label is too long to fit in the label's frame.

label.adjustsFontSizeToFitWidth = NO;
label.lineBreakMode = UILineBreakModeTailTruncation;

If you're using Interface Builder, you need to setup your label like this in the Inspector pane:

enter image description here

Rinat Khanov
  • 1,566
  • 10
  • 32