这里有一个UICollectionView,紫色细胞:只需用故事板,制约设置单元格的大小UICollectionView
很简单,我想细胞是集合视图的1/2宽度。 (所以TBC,这将是在集合视图细胞的两行排列。)
(集合视图仅仅是全屏,让每一个细胞都在屏幕宽度的一半。)
你如何做到这一点在故事板?
如果我试图以正常方式控制拖动,它基本上不起作用。
这些都是简单的完全静态单元格(不是动态的)。
对于谷歌搜索的人在这里,节省您的时间:这正是(2016),使两跨UICollectionView布局最简单的方法;细胞之间没有空隙。
// 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)
}
}
看到这个答案:http://stackoverflow.com/a/38028456/1630618 – vacawama