gpt4 book ai didi

ios - 自定义 Collection View 单元格无法正常工作

转载 作者:行者123 更新时间:2023-12-01 17:21:59 26 4
gpt4 key购买 nike

尝试创建自定义单元格,但是当我在单元格中添加标签时 collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath)不起作用。

没有标签单元用户界面:

enter image description here

iPad 模拟器 UI 是:

enter image description here

但是当我在单元格中添加标签时:

enter image description here

iPad 模拟器 UI 变为:

enter image description here

UICollectionViewDelegateFlowLayout在方法中:

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let emptySpace = 87*2 + 10
let remainingWidth = Int(self.view.frame.width) - emptySpace
return CGSize(width: remainingWidth/2, height: remainingWidth/2)
}

最佳答案

您是否使用 Xcode 11 (GM 2) 进行构建?我在实现 sizeForItemAt 时遇到了类似的问题.

似乎有些东西导致 Collection View 忽略 sizeForItemAt 中返回的大小而是使用 subview 的大小。

对我有用的是设置 Estimate SizeNone在 Interface Builder 的 Collection View 上。

这并不理想,尤其是如果您有很多单元格,但不幸的是,这是我发现的唯一解决方法。

setting <code>Estimated Size</code> to <code>None</code> on the collection view in Interface Builder

关于ios - 自定义 Collection View 单元格无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58447122/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com