0

I try inside of viewDidLoad the next code:

let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
layout.minimumInteritemSpacing = 0
layout.minimumLineSpacing = 0

but it doesn't work. What is the reason of this? Any ideas?

  • Does it crash? Is there a compiler error? – Qbyte Jul 06 '15 at 07:06
  • @Qbyte no. Nothing there =/ –  Jul 06 '15 at 07:06
  • @Orkhan what do you expect, and what happens? – Dániel Nagy Jul 06 '15 at 07:08
  • So what doesn't work exactly? Since the line spacing can be any value but not negative. – Qbyte Jul 06 '15 at 07:10
  • @Qbyte is zero negative? The space between rectangles is the same. I do not want these spaces around –  Jul 06 '15 at 07:12
  • @DánielNagy I want to set a space around rectangles to 0. I do not want these spaces around –  Jul 06 '15 at 07:13
  • @Orkhan and what if your view controller conforms to UICollectionViewDelegateFlowLayout and in the method collectionView:layout:minimumInteritemSpacingForSectionAtIndex: set the interim space to zero instead of what you did in view did load? – Dániel Nagy Jul 06 '15 at 07:23
  • @DánielNagy sorry, I did not understand you. Can you explain clearly? –  Jul 06 '15 at 07:47
  • @Orkhan So your viewcontroller, which contains your code above, should conform to **UICollectionViewDelegateFlowLayout** (e.g.: MyViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout), and after that, you will need the method **collectionView:layout:minimumInteritemSpacingForSectionAtIndex:**, and in that method return 0. – Dániel Nagy Jul 06 '15 at 08:02
  • @DánielNagy like this? `func collectionView(collectionView: UICollectionView, minimumInteritemSpacingForSectionAtIndex indexPath: NSIndexPath) { return 0 }`? –  Jul 06 '15 at 08:07
  • @DánielNagy but it prints me `Unexpected non-void return value in void function` error –  Jul 06 '15 at 11:13
  • @Orkhan sorry, this way: func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAtIndex section: Int) -> CGFloat { return 0 } – Dániel Nagy Jul 06 '15 at 11:18
  • @DánielNagy unfortunately, it doesn't help me, too. There the result: http://imgur.com/7GJjCOH –  Jul 06 '15 at 11:39
  • @Orkhan are the cell sizes set correctly? It looks like according to your screenshot, that the width and height should be equal to the screenwidth / 2. – Dániel Nagy Jul 06 '15 at 12:13
  • @DánielNagy yes, them sizes are correct =/ –  Jul 07 '15 at 04:49

1 Answers1

1

You should be set direction is horizontally. You need delete the code for the reason below:

"For a horizontally scrolling grid, this value represents the minimum spacing between items in the same column. This spacing is used to compute how many items can fit in a single line, but after the number of items is determined, the actual spacing may possibly be adjusted upward."

MeganZhou
  • 346
  • 3
  • 7