UICollection View Adjust Cell Size for Screen Size

Currently i have a collection view which takes up most of my screen at the 3.5 inch screen size.The collection view is 51 pixels from the top and 20 pixels from the bottom of the screen. I am using the cells with UIPageControl to create a paged layout, with one cell per page. When switching to the 4 inch size, using constraints i can get the collection view to expand into the new space (maintaining the 51 pixels from the top and 20 from bottom), but the cell size stays the same, so now there is a bunch of empty space at the top and bottom of the cell. I tried using constraints, but it appears you can’t set them for cells. How do i expand the cell size bigger to fill the empty space on the iPhone 5?

The collection view code is just

  • Adding rounded corner and drop shadow to UICollectionViewCell
  • how to create custom UICollectionViewCell
  • Swift: UICollectionViewCell didSelectItemAtIndexPath Change backgroundColor
  • UICollectionViewCell change cell size while scrolling
  • Where to determine the height of a dynamically sized UICollectionViewCell?
  • Auto Layout in UICollectionViewCell not working
  • - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
                  cellForItemAtIndexPath:(NSIndexPath *)indexPath
    MyCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
    return cell;

    The layout is setup in IB I want to get the layout working first before I add more

    iPhone 5 view. I want to fill the empty space

    iPhone 4 view

    2 Solutions Collect From Internet About “UICollection View Adjust Cell Size for Screen Size”

    You can either use the UICollectionViewFlowLayout method itemSize property to set the UICollectionViewCell size, or use the delegate method, collectionView:layout:sizeForItemAtIndexPath: if you need to dynamically set the sizes of the UICollectionViewCells.

    CollectionView layout Delegate that will help you to resize your Cell as you need.
    - (CGSize)collectionView:(UICollectionView *)collectionView 
              sizeForItemAtIndexPath:(NSIndexPath *)indexPath;