• 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
Re: Trying to create a collection view with evenly distributed cell
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trying to create a collection view with evenly distributed cell


  • Subject: Re: Trying to create a collection view with evenly distributed cell
  • From: Mike Abdullah <email@hidden>
  • Date: Sun, 25 Jan 2015 10:21:32 +0000

> On 25 Jan 2015, at 10:12, Aaron Lewis <email@hidden> 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 (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


References: 
 >Trying to create a collection view with evenly distributed cell (From: Aaron Lewis <email@hidden>)

  • Prev by Date: Trying to create a collection view with evenly distributed cell
  • Next by Date: Binding to a view's model object
  • Previous by thread: Trying to create a collection view with evenly distributed cell
  • Next by thread: Binding to a view's model object
  • Index(es):
    • Date
    • Thread