title: iOS UICollectionView header & footer location
body: <p>Working in <code>iOS 7</code>, how does one specify where the header &amp; footer boxes go in a <code>UICollectionView</code>?</p>
  
  <p>I have a custom <code>UICollectionViewFlowLayout</code>.  I have overwritten</p>
  
  <pre><code>-(void)prepareLayout
  
  -(NSArray*) layoutAttributesForElementsInRect:(CGRect)rect
  
  -(UICollectionViewLayoutAttributes*) layoutAttributesForSupplementaryViewOfKind: (NSString*)kind atIndexPath:(NSIndexPath*)indexPath
  </code></pre>
  
  <p>My problem is, I'm not sure how to specify header location.  I have already specified that a header exists in <code>prepareLayout</code>:</p>
  
  <pre><code>-(void)prepareLayout
  {
  [super prepareLayout];
  
  boundsSize = self.collectionView.bounds.size;
  midX = boundsSize.width / 2.0f;
  curIndex = 0;
  
  self.headerReferenceSize = CGSizeMake(CELL_SIZE, TITLE_HEIGHT);
  self.footerReferenceSize = CGSizeMake(0, 0);
  
  self.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  self.sectionInset = UIEdgeInsetsMake(TOP_INSET, LEFT_INSET, BOTTOM_INSET, RIGHT_INSET);
  self.minimumLineSpacing = LINE_SPACING;
  self.minimumInteritemSpacing = INTERIM_SPACING;
  self.itemSize = CGSizeMake(CELL_SIZE, CELL_SIZE);
  
  }
  </code></pre>
  
  <p>I just don't know the right property of my custom <code>FlowLayout</code> to set, as there doesn't seem to be something like "HeaderLocation" to set, either as a LayoutAttributes or in the layout object itself.  Right now, it is appearing to the side/between my images, when I'd like them to be appearing above each image (horizontal scroll).</p>
  
  <p>I have tried the following:</p>
  
  <pre><code>-(UICollectionReusableView*) collectionView: (UICollectionView*)collectionView viewForSupplementaryElementOfKind:(NSString*)kind atIndexPath:(NSIndexPath*)indexPath
  {
      NSLog(@"**ViewForSupplementaryElementOfKind called***");
  
      CGFloat centerX = collectionView.center.x;
      CGFloat centerY = collectionView.center.y;
      CGFloat titleWidth = [MyLayout titleWidth];
      CGFloat titleHeight = [MyLayout titleHeight];
  
      MyTitleView* titleView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:ImageTitleIdentifier forIndexPath:indexPath];
  
      titleView.frame = CGRectMake(centerX - titleWidth/2.0,
                                   0.0,
                                   titleWidth,
                                   titleHeight);
  
      return titleView;
  }
  </code></pre>
  
  <p>This doesn't work.  The title appears above overlapped with a bunch of other titles, then the moment I start scrolling (horizontally), they jump back into the wrong place, horizontally between the images rather than above.</p>
  
  <p>PS> Please do not suggest anything that has to do with NIB or XIB placement.  I am using a UICollectionView, NOT a UICollectionViewController, so I actually have no prototypical cell to work with.  The layout is being done entirely programatically -- from code alone -- so I can't simply open a XIB file and adjust the location of a text box.</p>