Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change tableview cell height according to label text swift?

Using a UITableView in Swift, could someone please help me automatically change the height of the cell based on the label, picture, and description please?

I want to dynamically change the cell size as the label text increases. i have already applied autolayout on the labels.

like image 893
xeb Avatar asked Sep 11 '25 20:09

xeb


1 Answers

Considering you have already applied constraints on the label. And also set your number of lines to 0. And then paste the following code in viewDidLoad method

tableView.estimatedRowHeight = 44.0
tableView.rowHeight = UITableViewAutomaticDimension
like image 146
Kadian Avatar answered Sep 13 '25 17:09

Kadian