facebookarchive / AsyncDisplayKit

Smooth asynchronous user interfaces for iOS apps.
http://asyncdisplaykit.org
Other
13.4k stars 2.2k forks source link

Question: ASTextNode single line of text with truncationAttributedString #243

Closed andyscott closed 9 years ago

andyscott commented 9 years ago

This is a question, not an issue.

What's the proper way to size and then layout an ASTextNode so that it shows exactly one line of text and truncates with truncationAttributedString at a fixed length? I need the calculated height of the text node in order to compute the rest of my layout.

At the moment I calculate the text size with an infinite width so that the text always renders in a single line. When I lay the node out, I use my fixed width instead of the calculated width.

Is there any other way to force the text to render as a single line? Should I calculate the size using a CGSizeMake(fixedLength, guessedHeightOfOneLine)? #152 talks of a label node-- one line text seems like the label's job.

secretiverhyme commented 9 years ago

Quoting @ocrickard in #152:

It's trivial to add maximumNumberOfLines property on ASTextNode as-is. The ASTextNodeRenderer would just have to set it on the NSTextContainer. We're open to Pull-requests!

Infinite-width hacks will work, but this is the most proper solution that I'm aware of. I don't see any reason not to expose maximumNumberOfLines on ASTextNode as well as any future ASLabelNode, if you feel like taking a stab at it! =]

andyscott commented 9 years ago

I'll take a stab early next week.

On Friday, January 23, 2015, Nadine Salter notifications@github.com wrote:

Quoting @ocrickard https://github.com/ocrickard in #152 https://github.com/facebook/AsyncDisplayKit/issues/152:

It's trivial to add maximumNumberOfLines property on ASTextNode as-is. The ASTextNodeRenderer would just have to set it on the NSTextContainer. We're open to Pull-requests!

Infinite-width hacks will work, but this is the most proper solution that I'm aware of. I don't see any reason not to expose maximumNumberOfLines on ASTextNode as well as any future ASLabelNode, if you feel like taking a stab at it! =]

— Reply to this email directly or view it on GitHub https://github.com/facebook/AsyncDisplayKit/issues/243#issuecomment-71261998 .