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
}
try this
make your number of lines for label as 0. because new line won't increase your char count at all
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.