0

I'm trying to make cells take as much width as possible, but I end up like this:

enter image description here

I have tried to remove margins, line spacing etc. in xcode:

enter image description here

But the horizontal margin is still huge, I want the same vertical margin applied.

Any ideas?

P.S attached example code:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.collectionView.delegate = self;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 9;
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    CollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];

    cell.backgroundColor = [UIColor whiteColor];
    return cell;
}
Daniyar
  • 2,975
  • 2
  • 26
  • 39
daisy
  • 22,498
  • 29
  • 129
  • 265
  • What do you think for this solution: http://stackoverflow.com/questions/13780138/dynamically-setting-layout-on-uicollectionview-causes-inexplicable-contentoffset ? – d.danailov Jan 24 '15 at 13:37
  • It seems that you ask the cell to size be 100 x 100? – ljk321 Jan 24 '15 at 13:38
  • @skyline75489 Yeah, I'm trying to override that. I dragged it to the view and it become 100x100 – daisy Jan 24 '15 at 14:41

1 Answers1

0

You set the Collection cell to be 100x100, and to be 3 at row.

So the UICollectionView is minimum 300/300. If you make the view to be 320(normal iPhone width), then the Collection View set padding between the cells automatically.

EDIT:

Try:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    CollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];

    cell.backgroundColor = [UIColor whiteColor];

    //3 because you wanted 3 cells. 18 is the min padding between the cell.
    cell.frame.size.width = collectionView.frame.size.width/3-18;

    return cell;
}
Paul Peelen
  • 10,073
  • 15
  • 85
  • 168
Altimir Antonov
  • 4,966
  • 4
  • 24
  • 26