{"action":"created","issue":{"url":"https://api.github.com/repos/mikeswanson/JBSpacer/issues/2","labels_url":"https://api.github.com/repos/mikeswanson/JBSpacer/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/mikeswanson/JBSpacer/issues/2/comments","events_url":"https://api.github.com/repos/mikeswanson/JBSpacer/issues/2/events","html_url":"https://github.com/mikeswanson/JBSpacer/issues/2","id":68833950,"number":2,"title":"extra margin seems to come from \"empty\" sections...","user":{"login":"williamnoto","id":6032433,"avatar_url":"https://avatars.githubusercontent.com/u/6032433?v=3","gravatar_id":"","url":"https://api.github.com/users/williamnoto","html_url":"https://github.com/williamnoto","followers_url":"https://api.github.com/users/williamnoto/followers","following_url":"https://api.github.com/users/williamnoto/following{/other_user}","gists_url":"https://api.github.com/users/williamnoto/gists{/gist_id}","starred_url":"https://api.github.com/users/williamnoto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/williamnoto/subscriptions","organizations_url":"https://api.github.com/users/williamnoto/orgs","repos_url":"https://api.github.com/users/williamnoto/repos","events_url":"https://api.github.com/users/williamnoto/events{/privacy}","received_events_url":"https://api.github.com/users/williamnoto/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-04-16T03:09:09Z","updated_at":"2015-04-16T04:26:15Z","closed_at":null,"body":"I really like this library but I'm struggling with some extra margin that piles up when I have empty sections... Checkout the piled up margin in the screenshot below... I *believe* those are from the internal margin padding of 3 empty sections.\r\n\r\n![screen shot 2015-04-15 at 9 56 53 pm](https://cloud.githubusercontent.com/assets/6032433/7173287/6ce0f7cc-e3ba-11e4-89d4-3d3f9a52d09d.png)\r\n\r\nin my viewDidLoad I invoke JBSpacer:\r\n\r\n    JBSpacerOption *option = [JBSpacerOption optionWithItemSize:[self itemWidth]\r\n                                                  minimumGutter:2.0f\r\n                                            gutterToMarginRatio:1.0f\r\n                                                  availableSize:self.collectionView.frame.size.width\r\n                                       distributeExtraToMargins:YES];\r\n    JBSpacer *spacer = [JBSpacer spacerWithOption:option];\r\n\r\n    [spacer applySpacingToCollectionViewFlowLayout:(UICollectionViewFlowLayout*)self.collectionViewLayout];\r\n\r\nand later I have:\r\n\r\n    - (CGFloat) itemWidth {\r\n        CGFloat margin = 5.0f;\r\n        CGFloat collectionViewWidth = self.collectionView.frame.size.width;\r\n        CGFloat width = (collectionViewWidth-(3*margin)) / 2;\r\n        return width;\r\n    }\r\n\r\n    - (CGSize)collectionView:(UICollectionView *)collectionView\r\n                  layout:(UICollectionViewLayout *)collectionViewLayout\r\n      sizeForItemAtIndexPath:(NSIndexPath *)indexPath\r\n    {\r\n        CGFloat length = [self itemWidth];\r\n        return CGSizeMake(length, length); // width, height\r\n    }\r\n\r\n    - (UICollectionReusableView*) collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath\r\n    {\r\n         UICollectionReusableView *reusableview = nil;\r\n        if (kind == UICollectionElementKindSectionHeader)\r\n        {\r\n            HNTileBrowsingHeaderViewCollectionReusableView * header = (HNTileBrowsingHeaderViewCollectionReusableView*)[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@\"HeaderView\" forIndexPath:indexPath];\r\n            NSArray * sectionArray = _sectionedResults[indexPath.section];\r\n            header.headerViewLabel.text = [_sectionHeaderLabels objectForKey:sectionArray];\r\n            reusableview = header;\r\n        }\r\n        return reusableview;\r\n    }\r\n\r\n    - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {\r\n        NSArray * itemArray = _visibleSectionedResults[section];\r\n        if (itemArray.count == 0)\r\n            return CGSizeZero;\r\n        CGSize size = CGSizeMake(320, (itemArray.count > 0 ? 30.0f : 1)); // width gets ignored.\r\n        return size;\r\n    }\r\n\r\nIf I comment out the JBSpacer from viewDidLoad I get this:\r\n\r\n![screen shot 2015-04-15 at 10 06 02 pm](https://cloud.githubusercontent.com/assets/6032433/7173360/b90efbd4-e3bb-11e4-8283-cbba333cec69.png)\r\n\r\nSee how that margin is gone from the empty sections (but now I don't have the nice layout in my collection? :(\r\n"},"comment":{"url":"https://api.github.com/repos/mikeswanson/JBSpacer/issues/comments/93636535","html_url":"https://github.com/mikeswanson/JBSpacer/issues/2#issuecomment-93636535","issue_url":"https://api.github.com/repos/mikeswanson/JBSpacer/issues/2","id":93636535,"user":{"login":"williamnoto","id":6032433,"avatar_url":"https://avatars.githubusercontent.com/u/6032433?v=3","gravatar_id":"","url":"https://api.github.com/users/williamnoto","html_url":"https://github.com/williamnoto","followers_url":"https://api.github.com/users/williamnoto/followers","following_url":"https://api.github.com/users/williamnoto/following{/other_user}","gists_url":"https://api.github.com/users/williamnoto/gists{/gist_id}","starred_url":"https://api.github.com/users/williamnoto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/williamnoto/subscriptions","organizations_url":"https://api.github.com/users/williamnoto/orgs","repos_url":"https://api.github.com/users/williamnoto/repos","events_url":"https://api.github.com/users/williamnoto/events{/privacy}","received_events_url":"https://api.github.com/users/williamnoto/received_events","type":"User","site_admin":false},"created_at":"2015-04-16T04:26:15Z","updated_at":"2015-04-16T04:26:15Z","body":"Hi Mike, \n\nThanks so much for your very prompt reply. That did seem to make a difference, except now I don’t seem to be getting the benefit of the spacer anymore. This probably sounds stupid (I’ve been up all day, I apologize) but can I capture the insets your tool defines so I can do something more nuanced than this:\n\n- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{\n    NSArray * itemArray = _visibleSectionedResults[section];\n    if (itemArray.count == 0)\n        return UIEdgeInsetsMake(CGFLOAT_MIN, CGFLOAT_MIN, CGFLOAT_MIN, CGFLOAT_MIN);\n    else\n        return UIEdgeInsetsMake(2,2,2,2);\n}\n\nthat is, how do I replace those 2’s with the values you calculate…\n\n> On Apr 15, 2015, at 10:31 PM, Mike Swanson <notifications@github.com> wrote:\n> \n> My guess is that you're correct that the insets are \"piling up\" in the empty sections. You may have to provide custom insets using the delegate for sections that are empty. This might help: http://stackoverflow.com/questions/13970950/uicollectionview-spacing-margins <http://stackoverflow.com/questions/13970950/uicollectionview-spacing-margins>\n> —\n> Reply to this email directly or view it on GitHub <https://github.com/mikeswanson/JBSpacer/issues/2#issuecomment-93628832>.\n> \n\n"}}