0

I have a collectionView that scrolls vertically. Inside the cells of that collectionView is another collectionView that I have a custom layout for. The layout is currently a subclass of UICollectionViewFlowLayout and I want the scroll direction to be horizontal. I have tried a variety of ways to set the scrollDirection to horizontal but none of them are working. How do I set scroll direction on a subclass of FlowLayout?

nyi
  • 3,123
  • 4
  • 22
  • 45
Ben B.
  • 1
  • 1
  • 1
    https://developer.apple.com/documentation/uikit/uicollectionviewflowlayout/1617720-scrolldirection – matt Apr 22 '18 at 22:33
  • Isn't working. That's the first thing I tried... – Ben B. Apr 22 '18 at 23:03
  • 1
    I guess I don't know what you mean by "isn't working". Setting a flow layout's scroll direction to horizontal does in fact make its scroll direction horizontal. And the fact that it's a subclass doesn't of itself change anything about that. – matt Apr 22 '18 at 23:04
  • Are you setting it too late ? On a completely different note, I feel it is an overkill to have a collection view inside a cell. You could use a `UIStackView` instead – user1046037 Apr 23 '18 at 01:11
  • It "wasn't working" for me either. I forgot to adjust the frame height. – Roselle Tanner Mar 11 '19 at 20:44

1 Answers1

2

You can easily change scroll direction by this code:

if let layout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout {
    layout.scrollDirection = .horizontal
}
Arash Etemad
  • 1,827
  • 1
  • 13
  • 29