Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOS how to truncate with ellipsis the last visible line of a paragraph?

I want to draw a paragraph (so i guess using CTFrameDraw or ctlinedraw) but i also need to truncate the text if it not fit in the defined area (rect). Normally we trim the last line by appending an ellipsis (ie the characters '...') How to do this ? How to do this with special char like '...[+]'

Also, i would like to know how to specify an indent (in pixel) for the very first line and if it's possible de define custom linespacing

and to finish, i need to know the exact final rect that will fit exactly the full paragraph (it's maybe lower than the defined area)

like image 727
zeus Avatar asked Jul 18 '16 09:07

zeus


1 Answers

 NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
    paragraph.lineBreakMode = NSLineBreakByTruncatingTail;
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraph range:NSMakeRange(0, [attributedString length])];
    descriptionLabel.attributedText = attributedString;

Use above code and to your UIelement label or button like this .U will get ellipses at the last line. And i am also tried to append string at end but i didnot. because in limited area the label shows fit information only remaining hides .On that line means except ellipses i tried some text.Sorry to giving less info.

like image 121
Pavankumar Avatar answered Nov 14 '22 23:11

Pavankumar