Aligning right to left on UICollectionView with contents

空扰寡人 提交于 2019-12-25 01:39:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!