HOW TO SET COLLECTION VIEW CELL SIZE IN IOS?

Glen Martin

Total Post:27

Points:191
Posted by  Glen Martin
 584  View(s)
Ratings:
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.
  1. Tarun Kumar

    Post:214

    Points:1642
    Re: How to set collection view cell size in iOS?

    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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!