What is the simplest way to allow the app user to swipe left or right through a list of items? Whether it is pictures, text, etc. I have tried several different ways including CollectionView and ScrollUI. Maybe I need more direction or more updated information that is current with Xcode.
An example would be like your Netflix app: when you swipe left or right through movies.
Xcode 13, Swift
CodePudding user response:
According to apple , for horizontal swipe - collection view is the best solution.(base class for collection view is also UIScrollView)
But according to the project need or the implementation of view, we can opt for UIscroll view.
CodePudding user response:
Do you want to have one row or more? If only one is needed the one UICollectionView
is more than enough. (Also it is the simplest most standard solution)
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .horizontal
self.myCollectionView.collectionViewLayout = layout
If you need many sections or rows....
For iOS13 I would suggest using a UICollectionView
with a UICollectionViewCompositionalLayout
.
That way you dont need complex setups like we used to do before (old method: A UICollectionView inside a UITableViewCell). Just a couple of extra lines.
Check this stack for more help Horizontally scrolling multiple sections with UICollectionViewCompositionalLayout