Two uilabels on uitable with dynamic height

女生的网名这么多〃 提交于 2020-01-11 13:09:07

问题


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.

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


回答1:


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.



来源:https://stackoverflow.com/questions/37638550/two-uilabels-on-uitable-with-dynamic-height

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!