具有两个UICollectionViewFlowLayout的UICollectionView

时间:2019-06-25 07:34:29

标签: ios swift uicollectionview uicollectionviewflowlayout

我正在开发iOS中的一个项目Swift。我们如何为一个collectionView分配两个不同的流布局?在这里,我需要UICollectionViewCell看起来像堆栈卡,为此,我正在使用CardsCollectionViewLayout(外部pod文件)。

new sqlite3.Database(
  pathname,
  sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE,
  err => {
    if (err) {
      console.log('eror' , err)
      return console.error(err.message);
    }
  })

它运行正常。但是问题是我无法通过设备宽度调整UICollectionViewCell宽度。为此,我需要使用UICollectionViewDelegateFlowLayout。

<input type="text" placeholder="$" class="form-control timing" id="runtime">  
<button type="button" id="changetime">Change time</button>

但是当我使用CardsCollectionViewLayout作为我的collectionView布局时,在上述方法中我没有得到回呼。

OR

有什么方法可以用UICollectionViewCell添加堆栈卡效果。

enter image description here

请帮助我。

1 个答案:

答案 0 :(得分:2)

您从错误的角度看待它,如果使用CardsCollectionViewLayout,则必须使用该布局提供的功能才能进行更改。 itemSize中有一个名为CardsCollectionViewLayout的属性,您可以设置该属性来定义卡的大小:

let layout = CardsCollectionViewLayout()
collectionView.collectionViewLayout = layout
layout.itemSize = CGSize(width: YOUR_WIDTH, height: YOUR_HEIGHT)
collectionView.dataSource = self
collectionView.delegate = self
collectionView.isPagingEnabled = true
collectionView.showsHorizontalScrollIndicator = false