Skip to content

Instantly share code, notes, and snippets.

@Kun-Yao-Lin
Created February 15, 2018 09:51
Show Gist options
  • Save Kun-Yao-Lin/b882cfc9859d647108a75cfde2be31d6 to your computer and use it in GitHub Desktop.
Save Kun-Yao-Lin/b882cfc9859d647108a75cfde2be31d6 to your computer and use it in GitHub Desktop.
#pragma mark Collection Layout Delegate
-(CGSize)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout *)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger item = indexPath.item;
if (item < [self.pageResult.results count] && indexPath.section == 0) {
//------------ 重點 ------------
NewsInfoCollectionViewCell *cell = (NewsInfoCollectionViewCell *) [collectionView cellForItemAtIndexPath:indexPath];
if (cell == nil) {
NSString *collectionViewCellClassName = NSStringFromClass(NewsInfoCollectionViewCell.class);
cell = [[[NSBundle mainBundle] loadNibNamed:collectionViewCellClassName
owner:nil
options:nil] firstObject];
}
[self renderCell:cell item:item];
cell.contentView.bounds = CGRectMake(0, 0, self.screenWidth, 10);
CGSize size = [cell systemLayoutSizeFittingSize:UILayoutFittingCompressedSize
withHorizontalFittingPriority:UILayoutPriorityDefaultHigh
verticalFittingPriority:UILayoutPriorityDefaultLow];
return size;
//------------ 重點結束 ------------
}
return [super collectionView:collectionView layout:collectionViewLayout sizeForItemAtIndexPath:indexPath];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment