2017-05-05 64 views

回答

1

您可以在UICollectionViewDelegateFlowLayout上使用sizeForItemAt indexPath方法。這將決定每個單元格的大小,並且可以配置爲相對於其他元素的大小(例如,您的view)。

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { 
    return CGSize(width: view.frame.width/2, height: 50) 
} 

只要確保你的集合視圖的deleagte設置,並委託符合UICollectionViewDelegateFlowLayout協議。

相關問題