in my project I want to use UICollectionView
with custom cells, I created collection view with custom cells but I want to use Different size of custom cell in my project I followed some tutorials but I din`t get it properly, and below I attached sample screen shot of what i really looking for collection view.
One of the possible ways to create this is to use sizeForItemAtIndexPath
and then return the size for your Cell
. Here are some useful links on Github which are exactly doing what you want :
As in the First image, some cells have buttons whereas others don't have. For this, you will have to create custom Cells i.e one custom cell with buttons and one without buttons. And inside your cellForItemAtIndexPath
function, you can define them with some if-else
condition.
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
if(firstCellConditionMet)
{
CustomCell1 *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CellIdentifier" forIndexPath:indexPath];
//Your code
return cell;
}
else{
CustomCell2 *cell2 = [collectionView dequeueReusableCellWithReuseIdentifier:@"CellIdentifier2" forIndexPath:indexPath];
//Your Code
return cell2;
}
}
}
This can be achieved by Collection View Flow Layout. You can create a flow layout and that layout will take care of different rows and how many elements are there in a row. Have a look at Ray Wenderlich's Tutorial here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With