Search code examples
iosobjective-cuicollectionviewright-to-leftuicollectionviewlayout

Aligning right to left on UICollectionView


this is a pretty straightforward question, but I haven't been able to find a definitive answer to it on SO (if I missed it, please correct me).

Basically, my question is: Is it possible to align UICollectionView row contents from right to left instead of from left to right?

In my research I've seen answers suggesting subclassing UICollectionViewFlowLayout, but I haven't been able to find an example where one was created for right-alignment.

My goal is to have 2 collection views set up like this:

Example

Any help is greatly appreciated!


Solution

  • You can get similar result by performing a transform on the collection view and reverse the flip on its content:

    First when creating the UICollectionView I performed a horizontal flip on it:

    [collectionView_ setTransform:CGAffineTransformMakeScale(-1, 1)];
    

    Then subclass UICollectionViewCell and in here do the same horizontal flip on its contentView:

    [self.contentView setTransform:CGAffineTransformMakeScale(-1, 1)];