I have a requirement of showing a UILabel with text that has two different styles (different colours, parts of the text bolded). This is solved easily enough by using the attrib
I missed truncation when I set linespacing, but all I had to to was add linebreakmode to paragraphstyle
NSMutableParagraphStyle *paragrahStyle = [[NSMutableParagraphStyle alloc] init];
[paragrahStyle setLineSpacing:1.5];
[paragrahStyle setLineBreakMode:NSLineBreakByTruncatingTail];
NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:@"Long string that truncates"];
[attributedText addAttribute:NSParagraphStyleAttributeName value:paragrahStyle range:NSMakeRange(0, [attributedText length])];
self.label.attributedText = attributedText;
You can set up an NSParagraphStyle
with any lineBreakMode
you please, and apply it to the string using NSParagraphStyleAttributeName
. I don't know if all of the values of NSLineBreakMode
are supported, but I have no reason to believe they aren't.
try this:
[_text drawWithRect:_textRect options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil];
They only way I've been able to get this to work is to not set a paragraph style.