Aashish Nagar
Aashish Nagar

Reputation: 1227

UICollectionCell position issue

enter image description hereCollectionView cell is not coming at correct position. I am using following code to create the Collection view

 let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
    layout.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
    layout.scrollDirection = UICollectionViewScrollDirection.Horizontal
    viewListCollection = UICollectionView(frame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height), collectionViewLayout: layout)
    layout.headerReferenceSize = CGSizeZero
    layout.footerReferenceSize = CGSizeZero

    viewListCollection.dataSource = self
    viewListCollection.delegate = self
    viewListCollection.backgroundColor = UIColor.whiteColor()
    viewListCollection.tag = 9999
    viewListCollection.registerNib(UINib(nibName: "SelectedContactCell", bundle: nil), forCellWithReuseIdentifier: "SelectedContactCell")
    viewListCollection.scrollEnabled = true
    viewListCollection.collectionViewLayout = layout
    self.addSubview(viewListCollection)

blue colour is of CollectionView and yellow colour is of CollectionViewCell . You can see the top distance of the cell, why this space is coming.And how to remove that?

Upvotes: 0

Views: 55

Answers (1)

Codobux
Codobux

Reputation: 1038

Try this in your viewDidLoad:

self.automaticallyAdjustsScrollViewInsets = false

Upvotes: 1

Related Questions