• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Trying to create a collection view with evenly distributed cell
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Trying to create a collection view with evenly distributed cell


  • Subject: Trying to create a collection view with evenly distributed cell
  • From: Aaron Lewis <email@hidden>
  • Date: Sun, 25 Jan 2015 18:12:44 +0800

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)];



    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?


--
Best Regards,
Aaron Lewis - PGP: 0x13714D33 - http://pgp.mit.edu/
Finger Print:   9F67 391B B770 8FF6 99DC  D92D 87F6 2602 1371 4D33
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Trying to create a collection view with evenly distributed cell
      • From: Mike Abdullah <email@hidden>
  • Prev by Date: Re: Detecting Managed Object Property Change From Undo Redo
  • Next by Date: Re: Trying to create a collection view with evenly distributed cell
  • Previous by thread: Re: Detecting Managed Object Property Change From Undo Redo
  • Next by thread: Re: Trying to create a collection view with evenly distributed cell
  • Index(es):
    • Date
    • Thread