I have a multiline UILabel in a UITableViewCell. I want to control the spacing between the lines, to compress the lines a bit closer together. I've read that the only way to control that "leading" is with Attributed Strings. So I've done this by making the label attributed instead of plain text, and then I set the lineHeightMultiple to 0.7 to compress the lines:
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineHeightMultiple = 0.7;
paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
paragraphStyle.alignment = NSTextAlignmentLeft;
NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"HelveticaNeue-Bold" size:15.0], NSFontAttributeName, paragraphStyle, NSParagraphStyleAttributeName, nil];
NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:@"Here is some long text that will wrap to two lines." attributes:attrs];
[cell.textLabel setAttributedText:attributedText];
The problem is, now the overall label is not centered vertically within the UITableViewCell.
How can I fix this? In the attachment below, you can see what I mean. The "compressed" multiline UILabel is higher up in each row than it should be, and doesn't vertically align with the arrow indicator on the right side any more.
Line height multiple changes the line hight of all lines, including the first line, so it all rides a little high in your label. What you really want is to adjust the line spacing, so the second line's starting base line is a little closer than the default.
Try replacing:
paragraphStyle.lineHeightMultiple = 0.7;
with:
paragraphStyle.lineSpacing = -5.0;
Adjust the line spacing value to taste.