UICollectionView: One Row or Column UICollectionView: One Row or Column xcode xcode

UICollectionView: One Row or Column


I am guessing you are using the built in Flow Layout.However, for your case, you should make a custom UICollectionView Layout.Make it subclass of UICollectionViewFlowLayout and add this code in the init method:

- (id)init {    if ((self = [super init])) {        self.scrollDirection = UICollectionViewScrollDirectionHorizontal;        self.minimumLineSpacing = 10000.0f;    }    return self; }

The minimumLineSpacing is the key to making it have one line here.

I hope this helps!


I found that setting the minimumLineSpacing just made my scroll area really big and that setting the minimumInteritemSpacing=big accomplished keeping the items in one scrolling row or column, centered in the middle of the collectionview.


There isn't a real reason to subclass if you can trust the type cast.

((UICollectionViewFlowLayout *)self.collectionView.collectionViewLayout).minimumLineSpacing = 1000.0f;

If you have your collectionView loaded from a nib you could also play around with the parameters in the Attributes and Size Inspectors.

Same goes for scroll direction.