Aligning right to left on UICollectionView
Without doing any Xtransform to the collection view, simply forced RTL:
YourCollectionView.semanticContentAttribute = UISemanticContentAttribute.forceRightToLeft
You can get similar result by performing a transform on the collection view and reverse the flip on its content:
First when creating the UICollectionView I performed a horizontal flip on it:
[collectionView_ setTransform:CGAffineTransformMakeScale(-1, 1)];
Then subclass UICollectionViewCell
and in here do the same horizontal flip on its contentView:
[self.contentView setTransform:CGAffineTransformMakeScale(-1, 1)];
By changing both flipsHorizontallyInOppositeLayoutDirection
and developmentLayoutDirection
, I was able to achieve a full screen RTL scroll where the first item was all the way to the right, and to reach the last cell, user will need to scroll to the left.
Like so:
class RTLCollectionViewFlowLayout: UICollectionViewFlowLayout {
override var flipsHorizontallyInOppositeLayoutDirection: Bool {
return true
}
override var developmentLayoutDirection: UIUserInterfaceLayoutDirection {
return UIUserInterfaceLayoutDirection.rightToLeft
}
}
In addition to Tawfik's answer:
You can also set UICollectionView's Semantic
property via Interface Builder:
More about this property: in this question