假設你知道所需的細胞高度,順應UICollectionViewDelegateFlowLayout
:
class Class_MyUIViewClass: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
and implement sizeForItemAtIndexPath
:
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
let desirednumberOfCollumns: CGFloat = 2
let width = collectionView.frame.width/desirednumberOfCollumns
return CGSize(width, yourHeight)
}
myfile.swift:49:10:實例方法 ':willDisplaySupplementaryView:forElementKind:的CollectionView(_在:)' '的CollectionView(的CollectionView:佈局sizeForItemAtIndexPath :)' 幾乎可選要求匹配協議的 'UICollectionViewDelegate' –
「CGSizeMake '在Swift中不可用 –
查看更新回答 – Rajat