I want to set the width of UICollectionViewCell
dynamically.
I found some code in swift and I want the code in Objective-C.
let flowLayout = col
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.