Rajamohan S
Rajamohan S

Reputation: 7269

How to align collection view cells Correctly in swift 2.0

I am having a problem with UICollectionView. I made a collection view it shows cells and it's elements perfectly. But, the problem is bottom cells are hidden when application open. After that, if I scroll to top, then the last row of collection view cells are open. How to correct them?? Please refer following screen shot. Thanks a lot!

It shows like below image(screenshot one)..

Screenshot one

But I want to show collection view cells like below image(screenshot two) without first time scrolling...

ScreenShot two

My Codings are :

//  ViewController.swift

import UIKit

class ViewController: UIViewController, UICollectionViewDataSource,UICollectionViewDelegate{

    @IBOutlet var collectionView: UICollectionView!

    var titles = ["Events","Visitor Space","Contact Us","Facebook","Videos","WebSite"]
    var icons = [UIImage(named: "cover"),UIImage(named: "cover"),UIImage(named: "cover"),UIImage(named: "cover"),UIImage(named: "cover"),UIImage(named: "cover")]

    override func viewDidLoad() {
        super.viewDidLoad()
    }


    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return titles.count
    }

    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = self.collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! HomeCollectionCells
        cell.homeLabel.text = titles[indexPath.row]
        cell.homeImage.image = icons[indexPath.row]
        return cell
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }        
}

Upvotes: 0

Views: 559

Answers (1)

Nirav D
Nirav D

Reputation: 72410

Try to add this in viewDidLoad

self.automaticallyAdjustsScrollViewInsets = false

Upvotes: 1

Related Questions