0

So, I'm developing an app with a structure like in the image, in which some of the sections scroll horizontally, the orthogonalScrollingBehavior has been sen to paging and the behaviour is working as expected, the only issue is that I'd like to have a UIPageControl there:

enter image description here

I've found several places which explain how to UPDATE the UIPageControl, like the following:

let section = NSCollectionLayoutSection(group: group)
section.orthogonalScrollingBehavior = .groupPaging
section.visibleItemsInvalidationHandler = { (items: [NSCollectionLayoutVisibleItem], offset: CGPoint, environment: NSCollectionLayoutEnvironment) in
    let page = (items.last?.indexPath.row ?? 0)
    // Update page controller here
}

But none of them explain how to put the UIPageControl, there's no view to attach it, no .xib or anything, is just some flow.

mtet88
  • 524
  • 6
  • 21

1 Answers1

0

One approach can be to register a page control (or a view which contains the page control) as a "supplementary view", which is then added to the NSCollectionLayoutSection as part of the boundarySupplementaryItems. When you dequeue the supplementary view, you store a reference to it somewhere, which you then access as part of your section.visibleItemsInvalidationHandler implementation.

Jonas W
  • 585
  • 4
  • 11