skip to Main Content

I’m trying to find a way to have a right to left UICollectionView using UICollectionViewCompositionalLayout but there’s no documentation about it. has anybody an idea?

please recommend anything than flipping the UICollectionView and the cells.

3

Answers


  1. Just add below lines in your view controller.

    extension UICollectionViewFlowLayout {
        
        open override var flipsHorizontallyInOppositeLayoutDirection: Bool {
            return true
        }
    }
    

    This is extension that over-ride and allow to flip horizontally for RTL layout.

    Login or Signup to reply.
  2. There is a trick it works for me:

        collectionView.transform = CGAffineTransform(scaleX: -1, y: 1)
    

    and in cellForItemAt :

        cell.transform = CGAffineTransform(scaleX: -1, y: 1)
    
    Login or Signup to reply.
  3. it depends on your usage if you use in tableviewcell you must set it to layoutSubviews() and if you use it in viewcontroller you must use in after viewdidload lifecycle

    collectionView.semanticContentAttribute = .forceRightToLeft
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search