collectionView分为三行,迅速4

时间:2019-02-11 09:44:28

标签: ios swift iphone uicollectionview

我需要创建一个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)
}

1 个答案:

答案 0 :(得分:0)

迅捷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中有一个“滚动方向”属性。您可以将其更改为水平或垂直。