title: UICollectionView layout, cells spaced far out
body: <p>I have a <code>UICollectionView</code> that displays images. My images are size 114x133 but for some reason the actual <code>UICollectionVewCell</code> is bigger than this (I can see this because I set the cell background to red). Because of this the view can display only 2 images and there is a huge gap between the two. I am implementing the following</p>
  
  <pre><code>- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
      UIImage* img = [UIImage imageNamed:@"thumbnail_frame.png"];
  
      return img.size;
  }
  
  - (UIEdgeInsets)collectionView:
  (UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
      return UIEdgeInsetsMake(1, 1, 1, 1);
  }
  </code></pre>
  
  <p>I am creating the cell's <code>contentview</code> programmatically (i.e init <code>imageView</code> etc).</p>
  
  <p>I face the same problem in a different view where I am creating the whole view programmatically. There I do:</p>
  
  <pre><code>   UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
      flowLayout.minimumInteritemSpacing=10;
      flowLayout.minimumLineSpacing= 30;
      flowLayout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
  
      if(collectionView != nil) {
          [collectionView removeFromSuperview];
      }
  
      CGRect frm= CGRectMake(45, 80, 250, 230);
  
      collectionView = [[UICollectionView alloc] initWithFrame:frm collectionViewLayout:flowLayout];//(0, 0, self.view.frame.size.width, self.view.frame.size.height) collectionViewLayout:flowLayout];
      collectionView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
      collectionView.clipsToBounds = YES;
      collectionView.layer.cornerRadius = 10.0;
      collectionView.dataSource = self;
      collectionView.delegate = self;
      [collectionView registerClass:[YourPicCollectionViewCell class] forCellWithReuseIdentifier:@"YourPicCell"];
  </code></pre>
  
  <p>Again there is either a big gap between two images, or if I make the width smaller, there are 3 images but the right-most one is half-visible.</p>
  
  <p>I tinkered with spacing but it doesn't seem to work. What could be the problem?</p>