Search code examples
iosswiftuikituilabel

How do I add new line in a UILabel inside a UITableViewCell?


I would like to have the bookSummary in a new line.

this is my current code, which sets a UILabel inside a UITableViewCell:

cell.detailTextLabel?.text = "\(books[indexPath.row].bookAuthor ?? "") - \(books[indexPath.row].bookSummary ?? "")"

UI Interface


Solution

  • Use \n as you are using in your string. and set the numberOfLines equal to 0 on the detailTextLabel

    cell.detailTextLabel?.text = "\(books[indexPath.row].bookAuthor ?? "") \n \(books[indexPath.row].bookSummary ?? "")"
    
    cell.detailTextLabel?.numberOfLines = 0