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

  • SEARCH
  • Home
  • 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 9225231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:31:33+00:00 2026-06-18T04:31:33+00:00

After much fiddling I’m beginning to suspect that there’s a bug in the spacing

  • 0

After much fiddling I’m beginning to suspect that there’s a bug in the spacing code of the UICollectionViewFlowLayout.

The problem is simple enough: I have five buttons I want to show on screen and I want the spacing between buttons to be 1 pt(2 pixels on retina display). To achieve this I have set the minimumInteritemSpacing to 1.0 and the cell width to 159.5 pt such that two cells will add up to 319 pt leaving a single point for the space. The problem appears when I want the third button to be the full width of the view because the flow layout causes the spacing to be 0.5 pt despite having been told to keep a minimum of 1.0. (see screenshot 1)

right layout wrong spacing

The code for setting up the spacing happens in

-(void)viewDidLoad
{
    UICollectionViewFlowLayout *flowLayout = (UICollectionViewFlowLayout *)[[self collectionView] collectionViewLayout];
    [flowLayout setMinimumInteritemSpacing:1.0];
    [flowLayout setMinimumLineSpacing:1.0];        
}

and the sizing of the cells in

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 2) {
        return CGSizeMake(320 ,151);
    }
    return CGSizeMake(159.5, 151);
}

If, on the other hand, I don’t make the third button full width the spacing behaves as expected though it shouldn’t affect the inter item spacing of a different row. (screenshot 2)

right spacing wrong layout

It should be noted that the CollectionView, CollectionViewCell and UILabel are set up in the storyboard and that I’ve already made sure the frame of the label visible in the screenshots is less than the cell’s width and I have also tried removing the label altogether but with the same result.

I can’t see why this is happening unless it is a bug in the flow layout code and I was looking for a sanity check here before submitting this as a bug.

  • 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-18T04:31:35+00:00Added an answer on June 18, 2026 at 4:31 am

    As mentioned in the comments, a combination of having to describe the problem here and a bit of subsequent thought caused me to realize that although minimumInteritemSpacing is a CGFloat it doesn’t make sense to pass it fractional values and its behaviour when you do so is undefined. This is because, on devices where there’s a 1:1 point to pixel ratio, there is no such thing as half a pixel. It just so happened that in some cases it behaved as I expected and thus blinded me to the real (and rather obvious) problem.

    Hopefully reading this can help others quickly realize the mistake.

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

Sidebar

Related Questions

It appears after much searching that there seems to be a common problem when
I'm having a bug in my code that's kicking my ass, so after much
After much looking, I found a bit of code that converts a BufferedImage to
after much debugging, I have determined that this code is ignoring the fast enumeration
After much fiddling, I've managed to install the right ODBC driver and have successfully
After much reading it seems that, really, the only way to read a number
Currently trying at add ajax to a site, after much reading I discovered that
After much searching and looking extensively, I have a question that is undoubtedly dumb
After much searching, I have not found a satisfactory method that is easy to
After much reading on ruby on rails and multiple database connections, it seems that

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.