This is the simplest solution.
Your UIViewController should implement UICollectionViewDelegateFlowLayout. Then the function below needs to be implemented on your UIviewController.
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let width = self.collectionView.frame.size.width / 2;
return CGSize(width: width, height: 230)
}
Furthermore, you can adjust each cell's spacing value on your storyboard. Click collectionView then see the size inspector.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…