Luke
Luke

Reputation: 9690

Does an NSAttributedString in a UILabel ignore the label’s numberOfLines property?

I need to increase the line spacing in a UILabel, so I’m using its attributedString to do so. Works fine, but it ignores the fact that I had also set the label’s numberOfLines to 2 – it only displays a single line, and truncates.

Any idea why this might be, what I can do about it, to still use two lines, but increase the spacing between them?

Upvotes: 2

Views: 1022

Answers (2)

Patrick Goley
Patrick Goley

Reputation: 5417

You can force the label to the correct size for your number of lines by calling sizeToFit after setting the attributedText. To avoid the problem of the shrinking label in your table view cells, reset the frame of the label to some default size before setting the attributedText and calling sizeToFit. This will prevent the label from continuously shrinking.

Upvotes: 1

Andy Kaminski
Andy Kaminski

Reputation: 142

It sounds like the frame of your UILabel isn't big enough. Try increasing the height and see if the problem persists.

Upvotes: 2

Related Questions