ios - 如何在 swift ios 中调整 Collection View 单元格高度?

标签 ios swift uicollectionview uicollectionviewcell uicollectionviewlayout

我的单元格包含标签和 TextView ,我想调整 TextView 的高度 enter image description here

单元格高度也应该调整。 请帮忙

谢谢

最佳答案

您有两种选择来实现此功能。

1)使用tableview并使用自动布局,以便单元格高度根据内容自动增加。

2)使用collection view,并在此方法中计算textview的高度,并在该方法sizeforitematindexpath中指定单元格大小。

这是第二种方法:

将文本设置为 TextView 后,将 TextView 框架更改为

textview.frame = CGRect(x: textview.frame.orgin.x, y:textview.frame.orgin.y, width: textview.frame.width, height = textview.contentSize.height)

现在在 cellForItemAtIndexPath 方法中计算 textview 高度并将该高度添加到单元格高度中。

关于ios - 如何在 swift ios 中调整 Collection View 单元格高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49233220/

相关文章:

javascript - Cordova AppRate 插件 "Rate it now"按钮在 iOS 上不起作用

ios - 当 UIPopoverController 处于事件状态时,UIWebView 未检测到点击

ios - 核心数据堆栈,, 'coreDataStack'的无可见@interface声明了选择器 'defaultStack'

ios - PDFKit - 使用 pageViewController 的 PDFView - 滑动到下一页时页面呈现缓慢

ios - 在 Apple TV 上使用多个控件管理焦点

ios - didSelectItemAt 无法从 SCLAlertView 工作

ios - 设置单元格数据后如何更新 UICollectionView 中单元格的大小?

ios - InputAccessoryView 不显示在 SubViewController 中

ios - 在不重新加载整个部分的情况下更新 UICollectionView 的标题内容

ios - 添加do时,try catch Google Analytic tracker got error