Snippets Collections
// install pod :: AlignedCollectionViewFlowLayout
// also assign class AlignedCollectionViewFlowLayout in storyboard

func setLayout() {

        let alignedFlowLayout = AlignedCollectionViewFlowLayout(horizontalAlignment: .justified, verticalAlignment: .center)

        statsCollectionView.collectionViewLayout = alignedFlowLayout

        statsCollectionView.delegate = self
        statsCollectionView.dataSource = self

    }
    
}

// MARK: - Collection View

extension GameStatsViewController : UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {

        print("sec :", section)

        return UIEdgeInsets(top: 0.0, left: 0, bottom: 0.0, right: 0)//here your custom value for spacing
    }

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

        var widthPerItem : CGFloat = 0
        var heightPerItem : CGFloat = 0

        widthPerItem = collectionView.frame.width / 3 - 7
        heightPerItem = widthPerItem + 5

        return CGSize(width:widthPerItem, height: heightPerItem)
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return namesArray.count
    }

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = statsCollectionView.dequeueReusableCell(withReuseIdentifier: "GameStatsCollectionViewCell", for: indexPath) as! GameStatsCollectionViewCell
        cell.name.text = namesArray[indexPath.row]
        cell.points.text = numbers[indexPath.row]
        
        return cell
    }
}
star

Fri Jan 27 2023 17:08:22 GMT+0000 (Coordinated Universal Time)

#ios #swift #collectionview #collection #cv
star

Sat Mar 26 2022 06:55:34 GMT+0000 (Coordinated Universal Time) https://www.hiration.com/app/resume-builder/design-view?content=android-developer&design=executive

#cv #link

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension