I am trying to make ellipse text on several lines inside a rectangle.
For NSLineBreakByTruncatingTail , the documentation states
The line is displayed so that the beginning is inserted into the container, and the missing text at the end of the line is indicated by an ellipse symbol. Although this mode works for multi-line text, it is more often used for single-line text.
but in this mode I get only one line:

However, with NSLineBreakByWordWrapping I do not get ellipsis for overlapping text:

Both images use the same code below (red background is a rectangle for drawing text) and, of course, the same size of the rectangle, so 2 lines should definitely match.
NSMutableParagraphStyle* paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; paragraphStyle.lineBreakMode = <<see above>>; paragraphStyle.alignment = NSTextAlignmentNatural; NSDictionary* drawingAttributes = [NSDictionary dictionaryWithObjectsAndKeys: [UIFont fontWithName:@"HelveticaNeue" size:36], NSFontAttributeName, paragraphStyle, NSParagraphStyleAttributeName, nil]; const CGRect rect = CGRectMake(...); [@"I do not get ellipsized in any way" drawInRect:rect withAttributes:drawingAttributes];
Is there a way to combine ellipsing with multi-line rendering, as the documentation says? With UILabel, I would only need to set the number of lines to something other than 1, but what about text rendering through code?
source share