Wrap Text in UITableView Custom Cell When It Reaches End of Screen (Swift)

10,202

Solution 1

Set label number of "Lines" to ZERO. And set "Line Breaks" to "Word Wrap"

Solution 2

Adding these two methods along with above code fixed the problem with custom font

tamilRow.textLabel?.numberOfLines=0
tamilRow.textLabel?.lineBreakMode = NSLineBreakMode.ByWordWrapping

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { return UITableViewAutomaticDimension }

func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return UITableViewAutomaticDimension
}
Share:
10,202
Navio53
Author by

Navio53

Updated on June 20, 2022

Comments

  • Navio53
    Navio53 almost 2 years

    I have a table that loads data from a database but the problem is if the text being loaded is too long, it goes off the screen. I'm trying to find a way for the text to go onto the next line and have the cell resize automatically to fit this change. Does anyone know how this is done? The cell has three labels but one of them is allowed to be multi-lined.

    EDIT:

    I got it to work using auto constraints but how can I resize the table cell so that the actual items fit inside the cell and do not go over the cell boundary?