Whatever Kitchen
Whatever Kitchen

Reputation: 700

TTTAttributedLabel Number of Lines Bugs

As per title above, did anyone ever face this problem when using TTTAttributedLabel?

Currently, if the label display only 1 line, it won't show up from the app. But if the labels size is more than 1 line, it working fine.

Is there anyone ever come across with this problem/bug? Hope this can help others also, thanks!

Upvotes: 2

Views: 3002

Answers (1)

BlueFish
BlueFish

Reputation: 5145

Based on these two posts:

It would seem that there is a problem with how CoreText measures height, and what is actually rendered when drawing the text, when it is a single line.

What seems to be happening is that the text is present, but the window to draw the text is still too small. So the solution is to manually set the frame of the TTTAttributeLabel to something bigger than what sizeToFit gives.

This involves two steps:

  1. Detecting when the height of the label is a single line
  2. Adjusting the height to something bigger

Something like this would do it:

if (labelHeight < kSingleLineLabelHeight) {
   labelHeight = kSingleLineLabelHeight
}

And then setting the label height accordingly.

Upvotes: 2

Related Questions