title: Uicollectionview weird gap
body: <p>I have collection view with custom flow layout and i wonder why i have extra space like that (right side):</p>
  
  <p><a href="https://i.stack.imgur.com/Q5eeV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Q5eeV.png" alt="enter image description here"></a></p>
  
  <p>It may hard to notice here, though, but you may see gray gap between right side and cell.</p>
  
  <p>Here is how i override standard collection view flow layout to remove horizontals gaps:</p>
  
  <pre><code>@implementation CalendarFlowLayout
  
  - (NSArray *) layoutAttributesForElementsInRect:(CGRect)rect {
      NSArray *answer = [super layoutAttributesForElementsInRect:rect];
      NSLog(@"layout blck passed");
      for(int i = 1; i &lt; [answer count]; ++i) {
          UICollectionViewLayoutAttributes *currentLayoutAttributes = answer[i];
          UICollectionViewLayoutAttributes *prevLayoutAttributes = answer[i - 1];
          NSInteger maximumSpacing = 0;
          NSInteger origin = CGRectGetMaxX(prevLayoutAttributes.frame);
  
          if(origin + maximumSpacing + currentLayoutAttributes.frame.size.width &lt; self.collectionViewContentSize.width) {
              CGRect frame = currentLayoutAttributes.frame;
              frame.origin.x = origin + maximumSpacing;
              currentLayoutAttributes.frame = frame;
          }
      }
      return answer;
  }
  
  @end
  </code></pre>
  
  <p>Cell size calculated as follow:</p>
  
  <pre><code>- (CGSize)collectionView:(UICollectionView *)collectionView
                    layout:(UICollectionViewLayout *)collectionViewLayout
    sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
  
  
      return CGSizeMake(SCREEN_WIDTH/7, (SCREEN_HEIGHT-NAVBAR_HEIGHT-STATUS_BAR_HEIGHT)/6);
  }
  </code></pre>
  
  <p>Those macros above look like that:</p>
  
  <pre><code>#define SCREEN_WIDTH  [[UIScreen mainScreen] bounds].size.width
  </code></pre>
  
  <p>It has been tested and it return correct output.</p>
  
  <p>Also, if i set width to SCREEN_WIDTH/3, there is will be no gap.</p>
  
  <p>How to remove it? Why is that happen?</p>