New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add property to know if the text is more than numberOfLines
long
#16
Comments
Hi @spadafiva, Your feature request makes sense to me, it's cumbersome to compare expected height vs actual over and over, and why not have Nantes report it, since it's already done the work to figure out if it's truncated or not. That being said, I wonder if this is the best spot for it to live. We won't know if we're truncated until after we start drawing the label, so if you set the text on the label and then right away ask if it's truncated, I'm not sure this flag will always be up to date. I don't think we can guarantee that Alternatively: Maybe something like:
|
Okay, I see. What do you think about adding a delegate method for when it updates then, if not an exposed property? |
Hey Chris, I submitted a PR with a solution that solves my problem and also works through the delegate so that it will return the correct info. Let me know if this is a suitable solution or if you have other feedback that could help to improve this kind of feature. |
Thanks for the PR! I'll take a look at it today. (Things have been busy for me the last couple days, sorry about that) |
What do you think of having a computed property on the label instead? Something like:
You have to query it after the frame is set, someplace like I think I like something more like this, because it takes all the timing out of Nantes and puts it on the user. Whenever you call it, it'll give you an accurate reading of its current state. If you call it before your frames are all the way laid out, it'll be truncated (probably, depending on your text you put in the label). Let me know what you think. Is this easier? Harder? More or less clear? |
Wouldn't this be the same to a client as just updating a boolean in the Alternatively, the other thing that could fix the issue that I'm having would be allowing something like a |
Is your feature request related to a problem? Please describe.
In my code I want to have a button for
Read more
that pops a full text description into a new page. It would be nice to know if the label is currently displaying all the text so that I can determine whether or not to hide theRead more button
Describe the solution you'd like
I think it should be possible to have a variable on the label class that gets updated in the
drawAttributedString(...
function that tells if the text is fully displayed. I would be happy to create a class with a PR to add this functionality if this solution makes sense. I'm open to any bikeshedding about the property name. I thinkisTruncated
,isShowingFullText
,hasHiddenText
could all be possibilities. Specifically, I think that we could put a flag before the for loop and then an update somewhere in here to update the status of that flag and update the label property after looping.Describe alternatives you've considered
It is possible to use a helper function to get the height of a view with a font size / attributed string, but it seems like there is a performance overhead and extra surface area that could potentially be removed.
The text was updated successfully, but these errors were encountered: