MohanSingh MohanSingh - 8 months ago 61
Swift Question

How to align collection view cells Correctly in swift 2.0

I am having a problem with UICollection View. 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() {

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() {



Try to add this in viewDidLoad

self.automaticallyAdjustsScrollViewInsets = false