简体   繁体   English

如何在Swift iOS中调整集合视图单元格的高度?

[英]How to adjust collection view cell height in swift ios?

My cell contains label and textview and i want to adjust the textview's height 我的单元格包含标签和textview,我想调整textview的高度 在此处输入图片说明

the cell height should also be adjusted. 单元高度也应调整。 please help 请帮忙

Thanks 谢谢

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。

Here is the second method: 这是第二种方法:

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.

相关问题 如何以编程方式为iOS中的集合视图单元格提供宽度和高度,Swift 3 - How to give width and height programatically for collection view cell in ios, swift 3 如何在swift中根据集合视图单元格内的标签内容自动调整高度? - How to automatically adjust height based on label content inside collection view cell in swift? 快速扩展Tableview单元格如何调整高度 - Swift expanding Tableview cell how to adjust height 如何使用集合视图单元格Swift iOS实现网格视图 - How to achieve Grid view using collection view cell swift ios 如何在Swift iOS中更改自定义“收藏夹视图”单元格的背景颜色? - How to change the background color of a custom Collection View cell in swift iOS? 如何在iOS Swift中设置特定索引的集合视图单元格? - How to set collection view cell of specific index in iOS Swift? 如何在集合视图中比较单元格的边框颜色(iOS,swift) - How to compare border color of a cell in collection view (iOS, swift) 根据内容动态调整tableview单元格的高度 - iOS Swift - Dynamically adjust the height of the tableview cell based on content - iOS Swift 如何在iOS中根据视图高度动态调整阴影? - How to adjust shadow dynamically with height of view in ios? Swift - CompositionalLayout - 集合视图单元格高度未根据图像高度计算 - Swift - CompositionalLayout - collection view cell height not calculated based on Image height
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM