Pavel  Bogart
Pavel Bogart

Reputation: 445

How to set constraints from page control indicator to the view

Can anybody help me please?:)

How can I set constraints in a storyboard for Page Control Indicator so when I am listing my collectionView pages the indicator isn't moving.

I've tried setting constraints for page control indicator, but there is just option to set it with cell frame. So when I list a collection view indicator appears again and again on each new page.

Screenshot:

enter image description here

Upvotes: 1

Views: 713

Answers (1)

bobski
bobski

Reputation: 172

You have to set the currentpage in the pageControl. The best is at the function scrollViewWillEndDragging:

override func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {

    let pageNumber = Int(targetContentOffset.pointee.x / view.frame.width)
    pageControl.currentPage = pageNumber

}

then it will work :)

Upvotes: 1

Related Questions