Alexey
Alexey

Reputation: 397

UICollectionView Layout

I have a UICollectionView. How can I move the first cell of UICollectionView? I need to get a result like on the image. Shift is different for each section.

enter image description here

Upvotes: 2

Views: 316

Answers (1)

BlueBear
BlueBear

Reputation: 7639

You need to create a dummy cell that you use for the first 3 cells of your collectionView. I went ahead and tested it out and it worked correctly. It's not completely desirable because you can't reference index 0 as being the visually apparent cell 0.

UICollectionViewCell *cell;

if (indexPath.row < self.dynamicNumberValue) {
    NSString *cellIdentifier = @"cellIdentifierDummy";
    cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
} else {
    NSString *cellIdentifier = @"cellIdentifier";
    cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
    collectionViewCell *collectionCell = (collectionViewCell *)cell;
    [collectionCell.cellLabel setText:[NSString stringWithFormat:@"%d", self.cellNumber]];
    self.cellNumber++;
}

enter image description here

Upvotes: 2

Related Questions