Customized Ellipsis on UILabel

- - posted in ios

Ellipsis (plural ellipses) is a series of dots that usually indicates an intentional omission of a word, sentence, or whole section from a text without altering its original meaning.1

In UILabel ellipsis ‘…’ show up when text is to long to fit in label frame:

alt text

Currenlty in UILabel there isn’t an easy way to customize the ellipses and change them to something like in Appstore reviews:

alt text

Introducing DSExpandingLabelWithCustomEllipsis:

Inspired by an answer on Stackoverflow - a) Store the full text for later expanding b) Trim the full text so it will fit in the required number of lines while considering the custom ellipsis.

DSExpandingLabelWithCustomEllipsis attributes:

  1. Using attributed text, for really custom ellipses.
  2. Finds the trimed text length using binary search.
  3. Does not use deprecated sizeWithFont
  4. Simple to use.

Usage:

1
2
3
4
5
6
self.myExpandingLabel.customEllipsisAttributedText = customEllipsis;
self.myExpandingLabel.attributedText = loremIpsum;
self.myExpandingLabel.didExpandBlock = ^(){
    NSLog(@"did tap label");
};
[self.myExpandingLabel setTruncatingForNumberOfLines:2];

Check it out on Github: DSExpandingLabelWithCustomEllipsis