Mikel Sanchez
Mikel Sanchez

Reputation: 2890

UICollectionView Different cells widths

enter image description here

Hi, I would like to make a design like this, I have a collectionView that has different sections, the first one has to be different... how can I do?

I have made different types of cells but it always has the same width as specified in the storyboard... Is there any way to set the width of the cell?

Thank you very much.

Upvotes: 2

Views: 1999

Answers (2)

Charles A.
Charles A.

Reputation: 11123

You will need to adopt the UICollectionViewDelegateFlowLayout protocol and implement the collectionView(_:layout:sizeForItemAtIndexPath:) method. This method is implemented to specify the size of individual items to the UICollectionViewFlowLayout object that does the layout in a collection view by default.

Here is a link to the relevant documentation.

Upvotes: 1

Soberman
Soberman

Reputation: 2586

You have to use UICollectionViewDelegateFlowLayout, specifically this method:

- (CGSize)collectionView:(UICollectionView *)collectionView
                  layout:(UICollectionViewLayout *)collectionViewLayout
  sizeForItemAtIndexPath:(NSIndexPath *)indexPath

Just return there the size you want at the section or indexPath you need.

Upvotes: 3

Related Questions