title: How to set the position of cells on UICollectionView
body: <p>I have an UIViewController which contains a UICollectionView. But the UICollectionView does not fill all the UIViewController. </p>
  
  <p>I find that there is space whose height equals the height of NavigationBar between the cell and the top edge of the UICollectionView. I don't know how I can set the cell position to (0,0) in the UICollectionView. (like this, the space is in the red rectangle)</p>
  
  <p><img src="https://i.stack.imgur.com/ejnqC.png" alt="enter image description here"></p>
  
  <p>I found this link <a href="https://stackoverflow.com/questions/17959637/how-do-i-set-the-position-of-a-uicollectionviewcell/17959755#17959755">How do I set the position of a UICollectionViewCell?</a> And I subclass UICollectionViewFlowLayout (the following are my code)</p>
  
  <p><strong>MZMCollectionViewFlowLayout.h</strong></p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  
  @interface MZMCollectionViewFlowLayout : UICollectionViewFlowLayout
  
  @end
  </code></pre>
  
  <p><strong>MZMCollectionViewFlowLayout.m</strong></p>
  
  <pre><code>#import "MZMCollectionViewFlowLayout.h"
  
  @implementation MZMCollectionViewFlowLayout
  
  - (CGSize)collectionViewContentSize
  {
      return [super collectionViewContentSize];
  }
  
  - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
  {
      return [super layoutAttributesForElementsInRect:rect];
  }
  
  - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
  {
      NSLog(@"MZMCollectionViewFlowLayout layoutAttributesForItemAtIndexPath");
      if (indexPath.section == 0 &amp;&amp; indexPath.row == 1) // or whatever specific item you're trying to override
      {
          UICollectionViewLayoutAttributes *layoutAttributes = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath];
          layoutAttributes.frame = CGRectMake(0,0,100,100); // or whatever...
          return layoutAttributes;
      }
      else
      {
          return [super layoutAttributesForItemAtIndexPath:indexPath];
      }
  }
  
  @end
  </code></pre>
  
  <p>and using it like this:</p>
  
  <pre><code>- (void)viewDidLoad
  {
      [super viewDidLoad];
      // Do any additional setup after loading the view.
  
      // hide the tool bar
      [self.navigationController setToolbarHidden:YES animated:YES];
  
      // set title
      self.navigationItem.title = @"User Album";
  
      [self.userAlbumView setCollectionViewLayout:[[MZMCollectionViewFlowLayout alloc] init]];
  }
  </code></pre>
  
  <p>But it does not work. The log <em>NSLog(@"MZMCollectionViewFlowLayout layoutAttributesForItemAtIndexPath");</em> doesn't show. And the blank is still there.</p>
  
  <p>Thanks for any help!</p>