Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does a multiline UILabel with linespacing remove the 3 dots at the end?

I have a problem with adding linespacing to my UILabel. If I don't use linespacing, I get 3 dots at the end of line 3 if the text is overflowing.

    UILabel *labelBlurb = [[UILabel alloc] initWithFrame:CGRectMake(marginLeft, 15+20, 295, 60)];
    [labelBlurb setNumberOfLines:3];
    [labelBlurb setText:blurb];
    [labelBlurb setLineBreakMode:NSLineBreakByTruncatingTail];
    [labelBlurb setAdjustsFontSizeToFitWidth:NO];
    [labelBlurb setTextColor:[UIColor colorWithRed:38.0/255.0 green:38.0/255.0 blue:38.0/255.0 alpha:1.0]];
    [labelBlurb setBackgroundColor:[UIColor clearColor]];
    [labelBlurb setFont:[UIFont fontWithName:@"HelveticaNeue" size:12]];

But when I add the attributed text like this:

    attributedString = [[NSMutableAttributedString alloc] initWithString:blurb];
    paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:3.5];
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [blurb length])];
    labelBlurb.attributedText = attributedString;
    [view addSubview:labelBlurb];

The 3 dots at the end disappears. How do I prevent the 3 dots from being removed when adding attributedText?

This is what I want WITH 3.5 linespacing:

Bacon ipsum dolor sit amet doner pork belly leberkas pastrami.

Short loin pastrami ribeye boudin tenderloin. Shoulder short ribs beef

pancetta. Salami biltong tongue ham hock beef ribs meatball.. <-- 3 dots

like image 483
Krueger Avatar asked Aug 05 '14 07:08

Krueger


1 Answers

Maybe it helps to set the lineBreakMode of the paragraphStyle-object to :NSLineBreakByTruncatingTail

like image 143
snod Avatar answered Oct 31 '22 02:10

snod