假设你知道所需的细胞高度,顺应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