UiCollectionView单元格问题

时间:2016-12-18 16:44:16

标签: ios swift uicollectionview

我有各种细胞的集合视图,但我有一个问题:

如果我在iPhone 6s模拟器上执行代码,我会得到这个(我希望在每台设备上都这样):

enter image description here

如果我在iPad Retina上执行它,我会得到这个:

enter image description here

如果我在iPhone 5上执行它(我看不到单元格): enter image description here

我该如何解决这个问题? 你能救我吗?

//更新:

如果我删除了uicollectionviewcell中的所有对象(在这种情况下只有图像视图)一切正常(iPad上的单元格相同,iPhone 5我看到了单元格)但是在单元格中我自然没有对象

1 个答案:

答案 0 :(得分:0)

您是否尝试过实施sizeForItemAtIndexPath以使宽度等于集合视图的宽度?

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
    return CGSize(width: collectionView.frame.size.width, height: /* your height */)
}