lucgian841
lucgian841

Reputation: 2002

Wrong layout in UICollectionView

In my app I use several UICollectionView. When the number of cell aren't so much I've an issue that's explained from this image:

enter image description here

I'm using this library for Horizontal layout FullyHorizontalCollectionView. Every time I reload the data of the UICollectionView I use the follow code [self.collectionView.collectionViewLayout invalidateLayout], but nothing changes. There's someone that has the same issue and can help me? Thank you

Upvotes: 0

Views: 179

Answers (1)

SAXENA
SAXENA

Reputation: 451

Add these lines in your viewDidLoad method, if collection view flow layout not working.

   override func viewDidLoad() {
    super.viewDidLoad()

    let layout = UICollectionViewFlowLayout()
    layout.scrollDirection = .vertical //.horizontal
    layout.sectionInset = UIEdgeInsets(top: 1, left: 1, bottom: 1, right: 1)
    layout.minimumLineSpacing = 1.0
    layout.minimumInteritemSpacing = 1.0
    //your collection view object
    myCollectionView.setCollectionViewLayout(layout, animated: true)
    myCollectionView.reloadData()
}

Upvotes: 1

Related Questions