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

Doesn't respect UILabel's numberOfLines property #30

Closed lightbow closed 8 years ago

lightbow commented 9 years ago

UILabel's numberOfLines property is ignored when using a THLabel. The text remains a single line.

tobihagemann commented 9 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. ;)

EmperiorEric commented 9 years ago

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.

tobihagemann commented 9 years ago

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.

EmperiorEric commented 9 years ago

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!

tobihagemann commented 8 years ago

Finally pushed your change to version 1.4.7, sorry the delay!