[英]How to adjust collection view cell height in swift ios?
You have two options to achieve this functionality. 您有两种选择来实现此功能。
1) Use a tableview and use autolayout so that cell height increases automatically according to the content. 1)使用表格视图并使用自动布局,以便单元格高度根据内容自动增加。
2) Use collection view and calculate the height of the textview in this method and specify the cell size in this method sizeforitematindexpath. 2)在此方法中使用集合视图并计算textview的高度,并在此方法中指定单元格大小sizeforitematindexpath。
Once the textis set to the textview then change the textview frame to 将文本设置为文本视图后,将文本视图框架更改为
textview.frame = CGRect(x: textview.frame.orgin.x, y:textview.frame.orgin.y, width: textview.frame.width, height = textview.contentSize.height)
Now calculate the textview height in cellForItemAtIndexPath method and add that height to the cell height. 现在,在cellForItemAtIndexPath方法中计算textview的高度,并将该高度添加到单元格的高度。
Hi this is the solution for collectionViewCell AutoAdjust cell height Size. 嗨,这是collectionViewCell自动调整像元高度大小的解决方案。 Check below link it should works fine.
检查下面的链接,它应该可以正常工作。
https://medium.com/@wasinwiwongsak/uicollectionview-with-autosizing-cell-using-autolayout-in-ios-9-10-84ab5cdf35a2
https://medium.com/@wasinwiwongsak/uicollectionview-with-autosizing-cell-using-autolayout-in-ios-9-10-84ab5cdf35a2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.