PageControl
  • October 26, 2023

Installation


Usage Example


import UIKit
import PageControl

class ViewController: UIViewController, UIScrollViewDelegate {

@IBOutlet weak var scrollView: UIScrollView!
@IBOutlet weak var pageControl: PageControl!

override func viewDidLoad() {
super.viewDidLoad()
scrollView.delegate = self
pageControl.numberOfPages = Int(scrollView.contentSize.width / scrollView.bounds.width)
pageControl.addTarget(self, action: #selector(pageControlDidChangeCurrentPage(_:)), for: .valueChanged)
}

@objc func pageControlDidChangeCurrentPage(_ pageControl: PageControl) {
scrollView.setContentOffset(CGPoint(x: scrollView.bounds.width * CGFloat(pageControl.currentPage), y: 0), animated: true)
}

func scrollViewDidScroll(_ scrollView: UIScrollView) {
if scrollView.isDragging || scrollView.isDecelerating {
let page = scrollView.contentOffset.x / scrollView.bounds.width
pageControl.setCurrentPage(page)
}
}
}

GitHub


View Github

#animation #ios #swift #uikit #uipagecontroller
YOU MIGHT ALSO LIKE...
SwiftSpeech

Recognize your user's voice elegantly without having to figure out authorization and audio engines. SwiftSpeech Examples Features Installation Getting Started ...

SwiftUIValueSlider

Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements iOS 14.0 Installation ...

Sliders

Sliders is a compilation of all my stylable drag based SwiftUI components. It provides a variety of unique controls as well ...

SlidingRuler

SlidingRuler is a Swift package containing a SwiftUI control that acts like an linear infinite slider or a finite, more precise ...

Skeletonui

SkeletonUI aims to bring an elegant, declarative syntax to skeleton loading animations. Get rid of loading screens or spinners and ...