Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8932233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:17:29+00:00 2026-06-15T09:17:29+00:00

I am using an UICollectionView with UICollectionViewFlowLayout . I set the size of each

  • 0

I am using an UICollectionView with UICollectionViewFlowLayout.

I set the size of each cell through the

collectionView:layout:sizeForItemAtIndexPath:

When switching from portrait to landscape, I would like to adjust the size of each cell to completely fit the size of the CollectionView, without leaving padding space between cells.

Questions:

1) How to change the size of a cell after a rotation event?

2) And, even better, how to make the layout where the cells always fit the entire size of the screen?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:17:29+00:00Added an answer on June 15, 2026 at 9:17 am

    1) You could maintain and swap out multiple layout objects, but there’s a simpler way. Just add the following to your UICollectionViewController subclass and adjust the sizes as required:

    - (CGSize)collectionView:(UICollectionView *)collectionView
                      layout:(UICollectionViewLayout *)collectionViewLayout
      sizeForItemAtIndexPath:(NSIndexPath *)indexPath
    {    
        // Adjust cell size for orientation
        if (UIDeviceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) {
            return CGSizeMake(170.f, 170.f);
        }
        return CGSizeMake(192.f, 192.f);
    }
    
    - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
    {
        [self.collectionView performBatchUpdates:nil completion:nil];
    }
    

    Calling -performBatchUpdates:completion: will invalidate the layout and resize the cells with animation (you can just pass nil to both block params if you’ve no extra adjustments to perform).

    2) Instead of hardcoding the item sizes in -collectionView:layout:sizeForItemAtIndexPath, just divide the height or width of the collectionView’s bounds by the number of cells you want to fit on screen. Use the height if your collectionView scrolls horizontally or the width if it scrolls vertically.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a UICollectionView programmatically. I've set its frame as follows: UICollectionView *collectionView
I want to delete multiple items from my HomeDirectory. I'm using UICollectionView with allowsMultipleSeletion
When using a UICollectionView with allowsMultipleSelection set to YES only a dozen items are
I've got this UICollectionView set up with a fetched results controller, using core data.
I'm making a horizontal picker by using a UICollectionView . It's simple enough: A
As titled. So I was successfully to put DataTable into my CollectionView with using:
Using mercurial, I've run into an odd problem where a line from one committer
I am using UICollectionView to generate several thumbnails in a Master View. This works
I am trying to implement UICollectionView and show images. I am using SDWebimage which
I have a collectionview that I am using to show thumbnails. I want it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.