好的,所以绿色方块将是图像,例如下面的行的大小将基于图像大小来确定它的外观。
我不确定如何获得3行,所有这些都是这样的。我尝试使用insetForSectionAtIndex
和insetForSectionAtIndex
进行设置,但它看起来并不合适。我附上了我的代码,以及下面的预期结果:
代码:
class Random : UIViewController, UICollectionViewDelegate, UICollectionViewDataSource{
var random = [1, 1, 1, 1, 1]
override func viewDidLoad() {
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("YoutubeResponsiveCell", forIndexPath: indexPath) as! UICollectionViewCell
return cell
}
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
/*Youtube Video selected*/
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 3
}
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 2
}
}
class XplainNavigationController : UINavigationController{
}
extension Random : UICollectionViewDelegateFlowLayout{
func collectionView(collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
var cellSizing : CGSize = UIImage(named: "imageHere")!.size
return cellSizing
}
func collectionView(collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
insetForSectionAtIndex section: Int) -> UIEdgeInsets {
return UIEdgeInsetsZero /*Spacing for each video.*/
}
func randomInt(min: Int, max:Int) -> Int {
return min + Int(arc4random_uniform(UInt32(max - min + 1)))
}
}