UILabel with NSAttributedString ignoring newlines

I have a UILabel, the number of lines is 0, it uses tail truncation. The label is large enough to fit two lines of text. If I give it a regular NSString with three lines of text, where each line is short and has \ n in the and field, it will display the first two lines and then an ellipse. It looks like: Line 1 Line 2 ...

But if I use NSAttributedString with the same text, it concatenates the 2nd and 3rd lines before trimming the result. It looks like: Line 1 Line 2Line 3

Nothing I tried without using CoreText, and fixing it in turn seems to make it work correctly.

Any suggestions?

+4
source share
1 answer
label.lineBreakMode = NSLineBreakByWordWrapping 
-one
source

Source: https://habr.com/ru/post/1497357/


All Articles