Abeeget
Abeeget

Reputation: 21

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

Upvotes: 0

Views: 50

Answers (1)

Mahyar Zhiani
Mahyar Zhiani

Reputation: 137

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

Upvotes: 1

Related Questions