tobihagemann / THLabel

UILabel subclass, which additionally allows shadow blur, inner shadow, stroke text and fill gradient.
https://tobiha.de
Other
665 stars 111 forks source link

No way of getting bounding box for text #53

Closed sgil closed 3 years ago

sgil commented 3 years ago

There is no way of generating a bounding box for the text given a fixed width, similar to NSAttributedString.boundingRect(with:options:context:)

If you use NSAttributedString.boundingRect(with:options:context:), estimate is wrong and text ends up getting cut off.

tobihagemann commented 3 years ago

I'm not sure what you're trying to achieve. Shouldn't intrinsicContentSize give you the correct size of the label?

sgil commented 3 years ago

I'm looking to have a fixed width of 200, with a variable height determined by the amount of text in the label. If I use intrinsicContentSize, it gives me a the size of the bounding box of the label if the text were all in one line.

tobihagemann commented 3 years ago

You should be able to set preferredMaxLayoutWidth to 200. Does that work for you?

sgil commented 3 years ago

Yes it does! Thank you so much, closing this issue out