Follow these steps:
one). Create a boolean variable named isExpanded to control extension / failure
2.) Add a goal and action to the show more button
[yourCellName.btnShowMore addTarget:self action:@selector(ShowMoreButtonClicked) forControlEvents:UIControlEventTouchUpInside];
3.) In sizeForItemAtIndexPath for height control add:
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { if (isExpanded && indexPath.row == 0) { return CGSizeMake(CGRectGetWidth(self.view.frame), calculated height for the expanded cell); } return CGSizeMake(CGRectGetWidth(self.view.frame), default height); }
4.) Then in the ShowMoreButtonClicked method
- (void)ShowMoreButtonClicked{ if (isExpanded) { isExpanded = FALSE; [collection_viewCus reloadItemsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:0]]]; } else { isExpanded = TRUE; [collection_viewCus reloadItemsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:0]]]; }}
5.) Add this line to your cellForItemAtIndexPath
[yourCellName layoutIfNeeded]
6.) Create and run
Mihawk
source share