Reputation: 529
I want to show 3*3 Collection View Dynamic Height cell any one known how to display this
thanks in Advance.!!!
Upvotes: 0
Views: 487
Reputation: 4391
Here's what you can use to have 3 * 3 Collection View
regarding iPhone screen size (assuming that your collectionView frame is set according to screen size) :
Swift
optional func collectionView(collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
var spaceBetweenCells = 12
var width = (self.collectionView.frame.size.width - spaceBetweenCells * 3) / 3
var height = (self.collectionView.frame.size.height - spaceBetweenCells * 3) / 3
return CGSizeMake(width, height)
}
Objective C
- (CGSize)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout *)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat spaceBetweenCells = 12;
CGFloat width = (self.collectionView.frame.size.width - spaceBetweenCells*3) / 3;
CGFloat height = (self.collectionView.frame.size.height - spaceBetweenCells*3) / 3;
return CGSizeMake(width, height);
}
Hope this helps.
Upvotes: 1