0

I tried with the following question:

Aligning right to left on UICollectionView but it's not achieved my goal.

What I was tried:

In viewDidLoad():

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

In cellForItemAtIndexPath():

cell.transform = CGAffineTransform(scaleX: -1.0, y: 1.0)

My current CollectionView is on the left, but I want it to look like the CollecitonView on the right.

dataSource = ["item1","item2","item3","item4","item5","item6"]

enter image description here

Update:

Change semanticContentAttribute of the collectionView to .forceRightToLeft

collectionView.semanticContentAttribute = .forceRightToLeft

by @RajeshKumar answered

I notice. items has spacing too much between two element for example item1 and item2 How can i reduce that the space and rest of things? ok for me. on the other hand I tried with layout.minimumInteritemSpacing = 0 but it is not worked for me and item3 not alinement right too.

Nazmul Hasan
  • 10,130
  • 7
  • 50
  • 73

2 Answers2

1

Change semanticContentAttribute of the collectionView to .forceRightToLeft

collectionView.semanticContentAttribute = .forceRightToLeft

It works

enter image description here

RajeshKumar R
  • 15,445
  • 2
  • 38
  • 70
  • I tried but let me check again because i my collection view in a table view cell – Nazmul Hasan May 28 '19 at 20:35
  • @NazmulHasan I have 2 collectonviews in same view controller. It works – RajeshKumar R May 28 '19 at 20:36
  • **I notice**. items has spacing too much between two element for example `item1 and item2` how can i fix that rest of things ok for me. on the other hand I tried with `layout.minimumInteritemSpacing = 0` but it is not worked for me. – Nazmul Hasan May 29 '19 at 03:27
0

In viewDidLoad():

 let alignedFlowLayout = collectionView.collectionViewLayout as? AlignedCollectionViewFlowLayout
 collectionView.transform = CGAffineTransform(scaleX: -1, y: 1)
 [enter link description here][1]alignedFlowLayout?.horizontalAlignment = .left

@Hemang comment worked for me.

If you have any subviews in your cell, then you have transform it as well. For e.g.

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

AlignedCollectionViewFlowLayout

Nazmul Hasan
  • 10,130
  • 7
  • 50
  • 73