2

I'm working on a project in iOS, Swift. How Can we assign one collectionView with two different flow layout? Here I need my UICollectionViewCell to look like a stack-card, for that, I'm using CardsCollectionViewLayout(external pod file).

myCollectionView.collectionViewLayout = CardsCollectionViewLayout()

And it is working fine. But the issue is I cant adjust the UICollectionViewCell width with device width. For that, I need to use UICollectionViewDelegateFlowLayout.

func collectionView(_ collectionView: UICollectionView,
                    layout collectionViewLayout: UICollectionViewLayout,
                    sizeForItemAt indexPath: IndexPath) -> CGSize {
    let nCol = 1
    let flowLayout = collectionViewLayout as! UICollectionViewFlowLayout
    let totalSpace = flowLayout.sectionInset.left
        + flowLayout.sectionInset.right
        + (flowLayout.minimumInteritemSpacing * CGFloat(nbCol - 1))
    let size = Int((collectionView.bounds.width - totalSpace) / CGFloat(nbCol))

    return CGSize(width: size, height: 284)
}

But When I use CardsCollectionViewLayout as my collectionView layout, I did not get the call back in the above method.

OR

Is there any way to add stack-card effect with my UICollectionViewCell.

enter image description here

Please help me.

Hilaj S L
  • 1,936
  • 2
  • 19
  • 31
  • Can you share which pod you are using? There must be an option in the pod itself to fit it to device width. @Hilaj – Pavan Kotesh Jun 25 '19 at 07:47
  • pod 'CardsLayout' – Hilaj S L Jun 25 '19 at 07:51
  • Possible duplicate of [UICollectionView with two flow layout](https://stackoverflow.com/questions/56749188/uicollectionview-with-two-flow-layout) – Mohmmad S Jun 25 '19 at 07:53
  • Please consider deleting one of your two identical questions , thanks https://stackoverflow.com/questions/56749188/uicollectionview-with-two-flow-layout – Mohmmad S Jun 25 '19 at 07:53

1 Answers1

2

You are looking it from a wrong prospective, if you use CardsCollectionViewLayout you have to use the function provided by that layout in order to change it. There's a property called itemSize in CardsCollectionViewLayout, which you can set to define the size of the cards:

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
LorenzOliveto
  • 7,796
  • 1
  • 20
  • 47