gpt4 book ai didi

ios - collectionView分为三行swift 4

转载 作者:行者123 更新时间:2023-11-29 06:01:33 27 4
gpt4 key购买 nike

我需要创建一个collectionView来显示一系列图像,分别为每张照片。我正在尝试重现您在图片中看到的内容,查看照片,然后向左或向右滚动查看下一张照片。我无法创建 collectionView

的布局

example image

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.datasource.count
}

//UICollectionViewDelegateFlowLayout - constraint della collecion view da innestare
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let width = (UIScreen.main.bounds.size.width - 3) / 3
let height = width
return CGSize(width: width, height: height)
}

最佳答案

swift 4:

  func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

//calculation of cell size
return CGSize(width: self.collectionview.frame.size.width,height: 180)
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
// indentation
return UIEdgeInsetsMake(0, 23, 20, 20)
}

如果你想水平或垂直拖动,在collectionview中有一个“滚动方向”属性。您可以将其更改为水平或垂直。

关于ios - collectionView分为三行swift 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54627673/

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