1

How would I create a staggered UICollectionView with the code I currently have?

- (void)viewDidLoad
{
    [self.collectionViewPack registerNib:[UINib nibWithNibName:@"CollectionViewItem" bundle:nil] forCellWithReuseIdentifier:kCellReuseIdentifier];
    self.collectionViewPack.backgroundColor = [UIColor whiteColor];

    [super viewDidLoad];

    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    [flowLayout setItemSize:CGSizeMake(150, 250)];
    [flowLayout setSectionInset:UIEdgeInsetsMake(8, 5, 5, 5)];
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];

    [self.collectionViewPack setCollectionViewLayout:flowLayout];
    [self.collectionViewPack setAllowsSelection:YES];
    self.collectionViewPack.delegate=self;
}

I'd like the columns to be able to scroll independently in their respective columns, but if that's not possible then staggered would be awesome too. Any ideas?

J-LO
  • 229
  • 1
  • 3
  • 17

1 Answers1

-1

You can follow the same method here as described for UITableView

https://stackoverflow.com/a/18746930/1616513

Then in sizeForItemAtIndexPath:

You just ask the cell to lay itself out and then call systemLayoutFittingSize on the cells contentView to get the calculated size.

Community
  • 1
  • 1
Samhan Salahuddin
  • 2,140
  • 1
  • 17
  • 24