How can I change the scroll direction in UICollectionView?
Swift 4 and 4.2
if let layout = collectionViewObj.collectionViewLayout as? UICollectionViewFlowLayout {
layout.scrollDirection = .vertical // .horizontal
}
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
Note too that it seems to be fine to call this in prepareForLayout
in your flow layout...
@interface LayoutHorizontalThings : UICollectionViewFlowLayout
@end
@implementation LayoutHorizontalBooks
-(void)prepareLayout
{
[super prepareLayout];
self.scrollDirection = UICollectionViewScrollDirectionHorizontal;
self.minimumInteritemSpacing = 0;
self.minimumLineSpacing = 0;
self.itemSize = CGSizeMake(110,130);
self.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
}
Set the scrollDirection
of the collection view's collectionViewLayout
.
Docs are here.