Swiftpack.co -  billp/SMPager as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
A lightweight, memory-efficient implementation of UIScrollView written in Swift.
.package(url: "https://github.com/billp/SMPager.git", from: "0.1.4")


Badge w/ Version Badge w/ Platform

SMPager or SimplePager is a lightweight, memory-efficient implementation of UIScrollView written in Swift. It works with reusable views the same way as UIKit's UITableView does.

enter image description here


  • Renders any type of UIView. (UIImageView, UILabel, UIViewController view, etc.)
  • Uses the least amount of memory required to render the views.
  • Supports infinite scrolling.
  • Populates your UIViews using delegation.


SMPager is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'SMPager', '~> 0.1'


In your ViewController initialize and add the pager to the superview.

import SMPager

class ViewController {
    let imageURLs = [

    lazy var pager: SMPager = {
        let pager = SMPager()
        pager.pagerDataSource = self
        pager.pagerDelegate = self
        pager.infiniteScrollingEnabled = true
        return pager

    func setupConstraints() {
        pager.translatesAutoresizingMaskIntoConstraints = false
            pager.leftAnchor.constraint(equalTo: self.view.leftAnchor),
            pager.rightAnchor.constraint(equalTo: self.view.rightAnchor),
            pager.topAnchor.constraint(equalTo: navBar.bottomAnchor),
            pager.bottomAnchor.constraint(equalTo: self.view.bottomAnchor)
    // MARK: View lifecycle
    override func viewDidLoad() {


Implement the SMPagerDelegate and SMPagerDataSource

// MARK: SMPagerDelegate
extension ViewController: SMPagerDelegate {
    func pageChanged(page: Int) {
        pageControl.currentPage = page

// MARK: SMPagerDataSource
extension ViewController: SMPagerDataSource {
    func numberOfViews() -> Int {
        return imageURLs.count
    func viewForIndex(_ index: Int, reusedView: UIView?) -> UIView {
        let imageView: UIImageView
        if let reuseView = reusedView as? UIImageView {
            imageView = reuseView
        } else {
            imageView = UIImageView()
            imageView.contentMode = .scaleAspectFill
        if let imageUrl = URL(string: imageURLs[index]) {
            imageView.kf.setImage(with: imageUrl)
        return imageView



// Enables/disables the infinite scrolling mode. You can set this variable anytime without the need to call reloadData(). Default value is false.
var infiniteScrollingEnabled: Bool 
// Set the SMPagerDelegate. (see bellow)
var pagerDelegate: SMPagerDelegate?
// Set the SMPagerDataSource. (see bellow)
var pagerDataSource: SMPagerDataSource?
// Get the visible page index (readonly)
var currentIndex: Int


// Moves to previous or next page. You can pass a boolean value if you want the transition between pages to be animated (default value is true).
func moveToPreviousPage(animated: Bool = true)
func moveToNextPage(animated: Bool = true)

// Moves to a specific page without animation.
func move(to page: Int)

// Reloads all the pager views.
func reloadData()

SMPagerDelegate methods

// Called when a page is changed.
func pageChanged(page: Int)

SMPagerDataSource methods

// Return the number of views to be rendered.
func numberOfViews() -> Int
// Return the view to be rendered for a specific index. reusedView is passed if it's available.
func viewForIndex(_ index: Int, reusedView: UIView?) -> UIView


Bill Panagiotopoulos, billp.dev@gmail.com


SMPager is available under the MIT license. See the LICENSE file for more info.


Stars: 11
Last commit: 1 year ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API