Husnain Kazmi
Husnain Kazmi

Reputation: 33

Two uilabels on uitable with dynamic height

I am trying to implement one English to Swedish learning app for Swift/IOS there I want to have two dynamic rows, data is coming from array and I tried my best to fix it out. I have seen approx. all stack overflow links as well but no success at all. See the screenshot, as the text is long, I cannot see it on the screen and the text is not coming on the second line as well. As, I add any constraint, both lines sometimes disappeared or only one lines comes.

I have seen this tutorial link as well but cannot get any success.

See the screenshot

Can any please see the code and fix it. Here is the complete code

Upvotes: 0

Views: 276

Answers (1)

Rajat
Rajat

Reputation: 11127

You have to use UITableViewAutomaticDimension to manage the cell height as per the content. For that you have to set the constraint of your labels from all the sides, ie Click on the PIN and then uncheck the 'Constraint from margin' check box and for both of your labels add constraints from Top, bottom, Left and Right side.As it is required if you want to use UITableViewAutomaticDimension.

Now in the ViewController in viewDidLoad method add this two line

self.tableView.estimatedRowHeight = 44.0
self.tableView.rowHeight = UITableViewAutomaticDimension

and then you your labels will display full text.

enter image description here

Upvotes: 4

Related Questions