When using NSMutableAttributedString and displaying multiple lines in UILabel, …(three-point reader) is not displayed

Asked 2 years ago, Updated 2 years ago, 52 views

Install UILabel on TableViewCell and
Line is fixed in 3 lines and
Configure LineBreakMode in TranslateTail and
JSON is trying to display variable length characters.

However, if there are more than four lines, the abbreviated three-point reader (…) will not be displayed.
I have the intention of specifying the space between the lines as follows, but
I can't do anything about it.
I also considered adding only the 3-point reader on the label myself.
I don't think I can get the coordinates of the last character before the 3rd line is cut off beautifully...
Could you lend me your wisdom?

Thank you for your cooperation.

// Specify custom LineHeight
CGFloat customLineHeight=19.0f;

// Set lineHeight in paragraph style
NSMutableParagrafStyle*paragrahStyle= [NSMutableParagrafStyle new];
paragrahStyle.minimumLineHeight=customLineHeight;
paragrahStyle.maximumLineHeight=customLineHeight;

// Generate NSAtributedString and set paragraph style
NSMutableAttributedString*attributedText=[NSMutableAttributedString alloc] initWithString:printLabel];
attributeText addAttribute: NSParographStyleAttributeName
                       value —ParagrahStyle
                       range —NSMakeRange(0, attributeText.length);

self.printLabel.attributedText=attributedText;

ios objective-c

2022-09-30 14:39

1 Answers

I don't think so, but don't you specify a new line mode in style and label it?

NSMutableParagrafStyle*paragrahStyle=[NSMutableParagrafStyle new];
paragrahStyle.minimumLineHeight=customLineHeight;
paragrahStyle.maximumLineHeight=customLineHeight;
paragrahStyle.lineBreakMode=NSLineBreakByTruncatingTail; // Added


2022-09-30 14:39

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.