两个uilabels uitable与动态高度 [英] Two uilabels on uitable with dynamic height

查看:103
本文介绍了两个uilabels uitable与动态高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为Swift / IOS实现一个英语到瑞典语的学习应用程序,我希望有两个动态行,数据来自数组,我尽力解决它。我见过约。所有堆栈溢出链接也没有成功。
请参阅屏幕截图,因为文字很长,我无法在屏幕上看到它,文字也不会出现在第二行。因为,我添加任何约束,两条线有时消失或只有一条线来。





任何请看代码并修复它。


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

解决方案

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.

这篇关于两个uilabels uitable与动态高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆