I have a textview which will be displaying four lines of text. If the text is too long, I need to show "See more" at the end of the fourth line. If text is small, I shouldn't show the "See more". I searched a lot, nothing helping me

- 1,155
- 1
- 11
- 26
3 Answers
In order to do this, you have to use an NSTextContainer. You can do some pretty fancy stuff with this, such as forming your text in a circle, triangle, or whatever UIBezierPath you can think of...
Here's apple's documentation: https://developer.apple.com/reference/uikit/nstextcontainer
You could then make a UIBezierPath shaped like this:
In the bottom right corner, you could have your "See more" button.
If the text is too big (see lineBreakMode), then enable the button with
seeMoreButton.enabled = true
If the text fits, use
seeMoreButton.enabled = false

- 1,779
- 3
- 24
- 32
You'll have to use the full Text Kit stack and lay the text out yourself. Apple explained how to do this for text truncation in a WWDC video a couple of years ago.

- 515,959
- 87
- 875
- 1,141
-
1[Actual WWDC video](https://developer.apple.com/videos/play/wwdc2013/220/) is here! – D4ttatraya Jul 19 '16 at 18:25
One way you could do this is have a max character count for the label and take the text up to that count and append with the "... See more" text like:
label.text = randomPost.text.substring(0, maxChars) + "... See more"
Note that I'm going off memory on how to substring in Swift, the signature I've provided may be off, just trying to convey the idea.

- 2,662
- 3
- 26
- 40
-
-
[This](http://stackoverflow.com/questions/25193520/determine-the-maximum-number-of-characters-a-uilabel-can-take) will give you maximum number of characters a UILabel can take! – D4ttatraya Jul 19 '16 at 19:13
-
@venky that's a different question. There's different ways to find out what device you're using. – rigdonmr Jul 19 '16 at 20:16