0

I have to show some text in UILabel and append read more if the text goes beyond 3 number of lines. It works fine if I set number of lines = 3 and trim the text to 120 characters or so. But if the text contains newline character then this fails.

How to handle this.

func formatText() -> String {
        var formatString = self.review_description
        var maxLimit = 140
        if self.review_link != nil {
            maxLimit  = 120
        }

        if formatString.count > maxLimit {
            let substring = formatString.dropLast(formatString.count - maxLimit)
            formatString = String(substring) + "... " + AppConstants.readMoreText
        }

        if self.review_link != nil {
            formatString = formatString + " \(AppConstants.reviewSourceText)"
        }

        return formatString
    }
Rajamohan S
  • 7,229
  • 5
  • 36
  • 54
Swati
  • 1,417
  • 1
  • 15
  • 35
  • [This solution](https://stackoverflow.com/questions/32309247/add-read-more-to-the-end-of-uilabel) didn't work for you? – TheTiger May 22 '18 at 09:54

1 Answers1

0

try this

make your number of lines for label as 0. because new line won't increase your char count at all

Abhay Singh
  • 255
  • 1
  • 8
  • If I do that and then call sizetoFit, it will size the label fully but I need to show only 3 lines and also append `...Read more` at the end – Swati May 24 '18 at 17:36