Hier ist ein UICollectionView, und die Zelle in lila:einfach mit Storyboard, Einschränkungen Größe der Zelle einzustellen, in UICollectionView
Ganz einfach, ich möchte, dass die Zellen 1/2 der Sammlung Ansicht sein, Breite. (So TBC, wird es eine zwei Reihen Anordnung von Zellen in der Sammlung sehen sein.)
(Die Sammlung Ansicht ist einfach Vollbild, so dass jede Zelle die halbe Bildschirmbreite.)
Wie Sie dies tun im Storyboard?
Wenn ich versuche, auf die normale Weise zu steuern, funktioniert es im Grunde nicht.
Dies sind einfache, völlig statische Zellen (nicht dynamisch).
Für all hier googeln, Ihre Zeit zu sparen: Hier ist genau (2016) der einfachste Weg, ein zwei über UICollectionView Layout zu machen; keine Lücken zwischen den Zellen.
// Two - two-across UICollectionView
// use a completely standard UIViewController on the storyboard,
// likely change scroll direction to vertical.
// name the cell identifier "cellTwo" on the storyboard
import UIKit
class Two:UICollectionViewController
{
override func viewDidLoad()
{
super.viewDidLoad()
let w = collectionView!.bounds.width/2.0
let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
layout.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
layout.itemSize = CGSize(width:w,height:w)
layout.minimumInteritemSpacing = 0
layout.minimumLineSpacing = 0
collectionView!.collectionViewLayout = layout
// Note!! DO NOT!!! register if using a storyboard cell!!
// do NOT do this:
// self.collectionView!.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
}
override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int
{ return 1 }
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
{ return 5 }
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
{
return collectionView.dequeueReusableCellWithReuseIdentifier("cellTwo", forIndexPath: indexPath)
}
}
Siehe diese Antwort: http://stackoverflow.com/a/38028456/1630618 – vacawama