Search code examples
iosswiftuilabelswift3multiline

How can I set a multiline UILabel inside UITableCell on Swift 3?


I am trying to set a multiline UILabel, inside an UITableCell.

That UILabel has a proportional width taking as reference the screen of the device (with a multiplier). The text inside of it can change so I need to fit on the UILabel being able to multiline when the width of the text is higher than the space of the UILabel width.

I tried using:

myLabel.lineBreakMode = .byWordWrapping
myLabel.numberOfLines = 0
myLabel.sizeToFit()

but it is always displayed on one line truncating the text that overflows the UILabel width.

How can I make my UILabel to be multiline?

EDIT: I cannot put breaklines to my text because I retrieve my texts from my database.

Thanks in advance!


Solution

  • Finally I was able to make my multiline UILabel adding this code:

    self.tableView.estimatedRowHeight = 50.0
    

    and reducing the multiplier value. It seems that the text could not fit on the height of the UITableCell.