I have a long string to show on UIButton
. I want to show the first 2 lines and if the text is longer than that - add a More button that will pop up an alertview
to show the full text. See the image
What is the best way to do that?
I have a long string to show on UIButton
. I want to show the first 2 lines and if the text is longer than that - add a More button that will pop up an alertview
to show the full text. See the image
What is the best way to do that?
Add your more button and wire it up the standard way, but set it to hidden. Then determine the length of the string and see if it is bigger than your textview. If so, set the more button to visible. When the button is pressed resize the textview and add more lines.
I'm not around a Mac at the moment so don't take this answer as gospel.
I would think that if you added a UILabel
as a subview of a UIButton
and setup the label to only show two lines before truncating, you could then detect if the displayed text was different than the actual text you used when you created the label by using NSString
's isEqualToString:
method. If the strings are different you know the label is truncated and you should show the 'more' button. I found this code on StackOverflow that returns an NSString
within an arbitrary NSRect
.