Home > DeveloperSection > Forums > How to set collection view cell size in iOS?
Glen Martin
Glen Martin

Total Post:27

Posted on    December-29-2015 7:27 AM

 iPhone iPhone  Ios  Objective C 

 1 Reply(s)
 293  View(s)
Rate this:
I have created an Photo album using UICollectionView.
I want to handle cell size by codding.
If it is possible then please provide me the code.
Thank you.

Tarun Kumar

Total Post:210

Posted on    December-29-2015 10:28 PM

To set the collection view cell size, you can use collectionView method sizeForItemAtIndexPath: .
Here is an example:

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)layout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  CGFloat width = (CGRectGetWidth(self.view.frame)/3.0f)-15);
  return CGSizeMake(width, (width *1.1f));
  // total 4 views displayed at a time;

I hope the above code is helpful for you, because I am using that code in our own sample.

Modified On Dec-29-2015 10:31:46 PM

Don't want to miss updates? Please click the below button!

Follow MindStick