Multi-line NSAttributedString with truncated text

后端 未结 9 2044
情书的邮戳
情书的邮戳 2020-12-23 14:55

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 co

9条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-23 15:30

    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.

提交回复
热议问题