问题
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"]
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.
回答1:
Change semanticContentAttribute of the collectionView to .forceRightToLeft
collectionView.semanticContentAttribute = .forceRightToLeft
It works
回答2:
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
来源:https://stackoverflow.com/questions/56349052/aligning-right-to-left-on-uicollectionview-with-contents