I have a UILabel with multiple line text. Label text is getting trimmed after 3 lines. I want to know what text is visible in that line. So that after that I can add Read More in it.
Asked
Active
Viewed 1,891 times
0
-
2Possible duplicate of [Calculate the range of visible text in UILabel](https://stackoverflow.com/questions/32311256/calculate-the-range-of-visible-text-in-uilabel) – Smartcat May 08 '18 at 16:19
-
iOS 11 Word Wrap makes this way harder. If you used CATextLayer or UITextView to show your text I could probably help but I am not getting anywhere near UILabel and IOS 11 word wrap – agibson007 May 09 '18 at 01:09
-
@Smartcat only reason it is not a duplicate is that the answer would not take into account iOS 11 Word Wrap changes to UILabel – agibson007 May 09 '18 at 04:42
-
@agibson007 Ok then how about this as a [duplicate SO](https://stackoverflow.com/questions/15113461/decrease-the-width-of-the-last-line-in-multiline-uilabel)? – Smartcat May 09 '18 at 04:47
1 Answers
1
Amazingly, this seems to be difficult. One solution that I found here is to determine which part of the string is displayed in which line. So it should be do-able in a label with not too many lines, although it is everything but elegant...

Reinhard Männer
- 14,022
- 5
- 54
- 116