简体   繁体   English

根据tableView的高度设置动态视图高度

[英]Set dynamic Height of view according to height of tableView

I want to create a view like this. 我想创建一个这样的视图。 For that I took one view. 为此,我采取了一种观点。 Inside it, label(Specification) and then for data of specification I took one tableView. 在它里面,贴上标签(Specification),然后获取一个tableView作为规范数据。 Data for specification could be 2,5,7 anything. 规格数据可能是2,5,7。 Means I am getting array of specification, which could have any no. 表示我正在获取规格说明数组,可能没有。 of elements. 的元素。 Now I want to set height of this view according to height of tableView and after this specification block I have another block which has y position according to specification view. 现在,我想根据tableView的高度设置该视图的高度,并且在此规范块之后,根据规范视图,我还有另一个块的y位置。 How can I do this? 我怎样才能做到这一点?

图片

图像2 This is the image of output what I am getting. 这是我得到的输出图像。 I don't want this scroll in tableView, instead of that I want it show with its maximum height in view. 我不希望此滚动出现在tableView中,而是希望它以最大高度显示在视图中。

You can set relation of the height constraint of tableView as <= . 您可以将tableView的高度限制关系设置为<= So that it will automatically adjust the height of the tableView, according to the data. 这样它就会根据数据自动调整tableView的高度。

Change the UITableView height after loading the content in table using GCD. 使用GCD在表中加载内容后更改UITableView高度。

Inner view of UITableView is based on ContentSize and outer view is based on frame size so just change frame size same as ContentSize . UITableView内部视图基于ContentSize ,外部视图基于帧大小,因此只需更改与ContentSize相同的帧大小。 Outer frame size depend on super view frame size but inner view size is depend on content. 外框尺寸取决于超视图框架尺寸,但内部视图尺寸取决于内容。

Follow the selected answer in Resizing UITableView to fit content 调整UITableView大小以适应内容时,请按照所选答案进行操作

Hope it will help you. 希望它会对你有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM