Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi-line NSAttributedString with truncated text

Tags:

ios

core-text

I need a UILabel subcass with multiline attributed text with support for links, bold styles, etc. I also need tail truncation with an ellipsis. None of the open source code that supports attributed text inside UILabels (TTTAttributedLabel, OHAttributedLabel, TTStyledTextLabel) seem to support tail truncation for multi-line text. Is there an easy way to get this?

like image 734
John Wright Avatar asked Sep 30 '11 14:09

John Wright


1 Answers

Maybe I'm missing something, but whats wrong with? :

NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:@"test"];  NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init]; style.lineBreakMode = NSLineBreakByTruncatingTail; [text addAttribute:NSParagraphStyleAttributeName                       value:style                       range:NSMakeRange(0, text.length)];  label.attributedText = text; 

This works perfectly and will add a ellipsis to the end.

like image 109
Toydor Avatar answered Sep 21 '22 07:09

Toydor