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

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


  • Subject: [RESOLVED] Re: Trying to create a collection view with evenly distributed cell
  • From: Aaron Lewis <email@hidden>
  • Date: Sun, 25 Jan 2015 23:16:24 +0800

Thanks Mike,

I followed the tutorial and did the exact same thing in objc, works.

On Sun, Jan 25, 2015 at 6:21 PM, Mike Abdullah <email@hidden> wrote:
>
>> 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?



--
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


  • Prev by Date: Re: Binding to a view's model object
  • Next by Date: Adding constrains for anonymous buttons
  • Previous by thread: Re: Binding to a view's model object
  • Next by thread: Adding constrains for anonymous buttons
  • Index(es):
    • Date
    • Thread