集合视图单元格宽度不正确

时间:2018-09-24 15:07:23

标签: ios swift uicollectionview autolayout

在更新到ios 12和xcode 10后,具有单元格大小的单元格的collectionView不再正常工作。

我在xcode中具有此布局

enter image description here

视图是这样的。

enter image description here

这就是现在的样子。

enter image description here

我尝试将collectionview视图设置为widht约束,并在

中进行了修改
len(df.loc[df['column B'].isnull()])

但什么也没发生。

1 个答案:

答案 0 :(得分:1)

您使用了错误的方法来设置像元大小。  代替collectionView(_:cellForItemAt:)使用collectionView:layout:sizeForItemAtIndexPath:

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
    let itemHeight = 60
    let itemWidth = UIScreen.main.bounds.width / 3
    return CGSize(width: itemWidth, height: itemHeight)
}

此外,您可以使用Interface Builder s Size Inspector设置项目大小,但是在这种情况下,单元格的大小将是绝对的。如果您希望它的大小为屏幕宽度的1/3,则需要使用布局委托。

相关问题