Tamannah
Tamannah

Reputation: 127

why does the dynamic collection cells in collection view doesnt display as given size and changes after scrolling in swift 3

I have a collection view.I need to display cells with varying width at sequences. First 4 cells get displayed as required but after that consecutive 5th image disappears and others are displayed but not in the desired manner. But it doesnot show in the simulator. The view gets distorted when scrolling the collection view.Please anyone help me out in swift 3.

Upvotes: 0

Views: 289

Answers (1)

JuicyFruit
JuicyFruit

Reputation: 2668

If you want to resize UICollectionViewCell try to implement this method, setting frame inside cellForRowAt is wrong.

func collectionView(_ collectionView: UICollectionView!, layout _: UICollectionViewLayout!, sizeForItemAtIndexPath indexPath: IndexPath!) -> CGSize {
    if indexPath.row%3 == 0 {
        return CGSize(width: 172, height: 120)
    } else {
        .....
    }//switch, if, whatever
}

Upvotes: 1

Related Questions