I have a UICollectionView in my storyboard based iOS app. When the device is in the portrait orientation I'd like it to scroll vertically, and when it's in Landscaper I'd like it to scroll horizontally.
In UICollectionView I can see the scrollEnabled member, but I can see no way to set the scroll direction. Have I missed something?
Do that in your storyboard. From identity inspector and select direction and give your direction.
Set the
scrollDirection
of the collection view'scollectionViewLayout
.Docs are here.
You should try this:
In Swift:
Kudos to Mundi and Dan Rosenstark for their answer, here's the swift 4.2 version.
Swift 4 and 4.2
Note too that it seems to be fine to call this in
prepareForLayout
in your flow layout...