Closed lightbow closed 8 years ago
Have you tried setting lineBreakMode
to NSLineBreakByWordWrapping
? numberOfLines
is being ignored, because Core Text doesn't support it natively. I'll put that info in the README eventually. ;)
This is definitely something worth working towards. UILabel with numberOfLines = 0
was a perfect centered label for long and short names. I dropped in THLabel
to get some better styling, and my layout broke.
I've found that in the intrinsicContentSize method if you respect preferredMaxLayoutWidth
from UILabel
that you can get something working.
CTFrameRef frameRef = [self frameRefFromSize:CGSizeMake(self.preferredMaxLayoutWidth, CGFLOAT_MAX) textRectOutput:&textRect];
I updated that line with preferredMaxLayoutWidth
and my layout went back to working as long as my constraints didn't allow the labels unlimited width. I had a few other spots in the app where I needed to manually set the preferredMaxLayoutWidth
for THLabel
but not UILabel
because UILabel
would give an intrinsic side respecting words while THLabel
only seemed to respect characters.
I'll try to dig into the wrapping more when I find a bit of time.
Love THLabel
though. Great class for styling.
Thanks for your pull request! Oh man, I wanted to integrate preferredMaxLayoutWidth
last year, but totally forgot about that, so thanks again! :+1:
Yeah, getting the same behavior as UILabel
regarding multiple lines / wrapping is hard.
Yea, I'm on a tight deadline with this game so very much a "whatever works" stage. But I really like this class so as I use it in projects with more time, I'm hoping to contribute more.
Thanks for making it!
Finally pushed your change to version 1.4.7, sorry the delay!
UILabel's numberOfLines property is ignored when using a THLabel. The text remains a single line.