Adding padding to first and last cell of UICollectionView
<p>I have subclassed UICollectionViewFlowLayout to get horizontal UICollectionView with paging like behavior. It works perfectly fine as long as UICollectionViewCell is not first of last cell. Images attached below. </p>

<p><a href="https://i.stack.imgur.com/llcJg.png" rel="noreferrer"><img src="https://i.stack.imgur.com/llcJg.png" alt="enter image description here"></a>
<a href="https://i.stack.imgur.com/j0s0D.png" rel="noreferrer"><img src="https://i.stack.imgur.com/j0s0D.png" alt="enter image description here"></a></p>

<p>Do I need to override something in my UICollectionViewFlowLayout besides following ?</p>

<pre><code>- (CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset withScrollingVelocity:(CGPoint)velocity
{
CGFloat offSetAdjustment = MAXFLOAT;
CGFloat horizontalCenter = (CGFloat) (proposedContentOffset.x + (self.collectionView.bounds.size.width / 2.0));

CGRect targetRect = CGRectMake(proposedContentOffset.x,
                               0.0,
                               self.collectionView.bounds.size.width,
                               self.collectionView.bounds.size.height);

NSArray *array = [self layoutAttributesForElementsInRect:targetRect];
for (UICollectionViewLayoutAttributes *layoutAttributes in array)
{
    if(layoutAttributes.representedElementCategory == UICollectionElementCategoryCell)
    {
        CGFloat itemHorizontalCenter = layoutAttributes.center.x;
        if (ABS(itemHorizontalCenter - horizontalCenter) &lt; ABS(offSetAdjustment))
        {
            offSetAdjustment = itemHorizontalCenter - horizontalCenter;
        }
    }
}

CGFloat nextOffset = proposedContentOffset.x + offSetAdjustment;

do {
    proposedContentOffset.x = nextOffset;
    CGFloat deltaX = proposedContentOffset.x - self.collectionView.contentOffset.x;
    CGFloat velX = velocity.x;

    if(deltaX == 0.0 || velX == 0 || (velX &gt; 0.0 &amp;&amp; deltaX &gt; 0.0) || (velX &lt; 0.0 &amp;&amp; deltaX &lt; 0.0))
    {
        break;
    }

    if(velocity.x &gt; 0.0)
    {
        nextOffset += [self snapStep];
    }
    else if(velocity.x &lt; 0.0)
    {
        nextOffset -= [self snapStep];
    }
} while ([self isValidOffset:nextOffset]);

proposedContentOffset.y = 0.0;

return proposedContentOffset;
}
    - (BOOL)isValidOffset:(CGFloat)offset
{
    return (offset &gt;= [self minContentOffset] &amp;&amp; offset &lt;= [self maxContentOffset]);
}

- (CGFloat)minContentOffset
{
  return -self.collectionView.contentInset.left;
}

- (CGFloat)maxContentOffset
{
    return [self minContentOffset] + self.collectionView.contentSize.width -      self.itemSize.width;
}

- (CGFloat)snapStep
{
return self.itemSize.width + self.minimumLineSpacing;
}
</code></pre>

<p>Any pointers/ comments will be useful. </p>