Aligning right to left on UICollectionView with co

2019-08-27 18:19发布

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.

2条回答
萌系小妹纸
2楼-- · 2019-08-27 18:33

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

查看更多
一夜七次
3楼-- · 2019-08-27 18:34

Change semanticContentAttribute of the collectionView to .forceRightToLeft

collectionView.semanticContentAttribute = .forceRightToLeft

It works

enter image description here

查看更多
登录 后发表回答