Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: soffes/sstoolkit
...
head fork: baz/sstoolkit
compare: master
Checking mergeability… Don’t worry, you can still create the pull request.
  • 15 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
View
15 SSToolkit/SSCollectionView.h
@@ -548,6 +548,21 @@ typedef enum {
@optional
/**
+ Asks the delegate for the amount of inter-item spacing in a row.
+
+ @param aCollectionView The collection view object requesting this information.
+
+ @param section The section the item is located in.
+
+ @param proposedSpacing The spacing that the collection view has calculated is the ideal amount.
+
+ @return The alternate item row inter-item spacing.
+ */
+- (CGFloat)collectionView:(SSCollectionView *)aCollectionView itemRowSpacingForSection:(NSUInteger)section proposedSpacing:(CGFloat)proposedSpacing;
+
+@optional
+
+/**
Tells the delegate the collection view is about to draw an item for a particular index path.
A collection view sends this message to its `delegate` just before it uses item to draw a portion of a row, thereby
View
11 SSToolkit/SSCollectionView.m
@@ -452,6 +452,8 @@ - (void)insertSections:(NSIndexSet *)sections withItemAnimation:(SSCollectionVie
- (void)deleteSections:(NSIndexSet *)sections withItemAnimation:(SSCollectionViewItemAnimation)animation {
+ // Clear cache to avoid an out of bounds crash when inserting new sections in place of the deleted ones
+ [_sectionCache removeAllObjects];
[_tableView deleteSections:sections withRowAnimation:(UITableViewRowAnimation)animation];
}
@@ -636,7 +638,12 @@ - (NSUInteger)_numberOfRowsInSection:(NSUInteger)section {
- (CGFloat)_itemSpacingForSection:(NSUInteger)section {
CGSize itemSize = [self _itemSizeForSection:section];
NSUInteger itemsPerRow = [self _numberOfItemsPerRowForSection:section];
- return roundf((self.frame.size.width - (itemSize.width * (CGFloat)itemsPerRow)) / (itemsPerRow + 1));
+ CGFloat spacing = roundf((self.frame.size.width - (itemSize.width * (CGFloat)itemsPerRow)) / (itemsPerRow + 1));
+ if ([_delegate respondsToSelector:@selector(collectionView:itemRowSpacingForSection:proposedSpacing:)]) {
+ spacing = [_delegate collectionView:self itemRowSpacingForSection:section proposedSpacing:spacing];
+ }
+
+ return spacing;
}
@@ -655,7 +662,7 @@ - (NSArray *)_itemsForRowIndexPath:(NSIndexPath *)rowIndexPath {
NSUInteger startIndex = itemsPerRow * row;
NSUInteger endIndex = (NSUInteger)fmin(totalItems, startIndex + itemsPerRow);
- NSMutableArray *items = [[[NSMutableArray alloc] initWithCapacity:endIndex - startIndex] autorelease];
+ NSMutableArray *items = [[[NSMutableArray alloc] initWithCapacity:abs(endIndex - startIndex)] autorelease];
for (NSUInteger i = startIndex; i < endIndex; i++) {
NSIndexPath *itemIndexPath = [NSIndexPath indexPathForRow:i inSection:rowIndexPath.section];
View
11 SSToolkit/SSCollectionViewItemTableViewCell.m
@@ -52,13 +52,20 @@ - (void)dealloc {
- (void)layoutSubviews {
__block CGFloat x = _itemSpacing;
-
+ // Ensure whole row is centered
+ NSUInteger numItems = (NSUInteger) self.bounds.size.width / _itemSize.width;
+ CGFloat totalWidth = _itemSize.width * numItems + _itemSpacing * (numItems + 1);
+ CGFloat xOrigin = (self.bounds.size.width - totalWidth) / 2;
+
[_items enumerateObjectsUsingBlock:^(id object, NSUInteger index, BOOL *stop) {
SSCollectionViewItem *item = (SSCollectionViewItem *)object;
- item.frame = CGRectMake(x, 0.0f, _itemSize.width, _itemSize.height);
+ item.frame = CGRectIntegral(CGRectMake(xOrigin + x, 0.0f, _itemSize.width, _itemSize.height));
+
x += _itemSize.width + _itemSpacing;
}];
+
+ self.frame = CGRectIntegral(self.frame);
}

No commit comments for this range

Something went wrong with that request. Please try again.