> On 25 Jan 2015, at 10:12, Aaron Lewis <the.warl0ck.1...@gmail.com> wrote:
> 
> Hi,
> 
> I'm trying to create a 3 cell per row collection, and I want no margin
> (horizontally or vertically) between each cell.
> 
> So in xcode I set Min Spacing For Cells / For Lines to 1, Indicator
> insets (all 4 values) to 0, then I write code like this:
> 
> - (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 setFrame: CGRectMake (cell.frame.origin.x,
> 
>                                cell.frame.origin.y,
> 
>                                self.collectionView.frame.size.width / 3,
> 
>                                cell.frame.size.height)];

Time to back up and re-learn the basics of collection views. Collection views 
are in charge of the layout of their cells, including sizing. You don’t get to 
set the cell’s frame directly.

Instead you want to set the collection view’s item size appropriate to match 
the view’s width. This may help: 
http://dativestudios.com/blog/2015/01/08/collection_view_layouts_on_wide_phones/
> 
> 
> 
>    cell.backgroundColor = [UIColor whiteColor];
> 
>    return cell;
> 
> }
> 
> If you run that code you will see the horizontal margin still exists
> and is very huge compared to the vertical one.
> 
> What's the correct way to do it?

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to