Latest 0.2.0
Homepage https://github.com/3lvis/PaginatedScrollView
License MIT
Platforms ios 9.0, tvos 9.0, requires ARC
Frameworks UIKit
Authors

Version
Carthage compatible
platforms
License

Simple paginated UIScrollView subclass that supports UIViewControllers as pages. It handles rotation pretty well, too.

PaginatedScrollView

Usage

import UIKit

class RootController: UIViewController {
    var pages: [UIViewController] {
        let firstController = UIViewController()
        firstController.view.backgroundColor = UIColor.redColor()

        let secondController = UIViewController()
        secondController.view.backgroundColor = UIColor.greenColor()

        let thirdController = UIViewController()
        thirdController.view.backgroundColor = UIColor.purpleColor()

        return [firstController, secondController, thirdController]
    }

    lazy var scrollView: PaginatedScrollView = {
        let view = PaginatedScrollView(frame: view.frame, parentController: self, initialPage: 0)
        view.viewDataSource = self

        return view
    }()

    override func viewDidLoad() {
        super.viewDidLoad()

        view.addSubview(scrollView)
    }

    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()

        scrollView.configure()
    }
}

extension RootController: PaginatedScrollViewDataSource {
    func numberOfPagesInPaginatedScrollView(paginatedScrollView: PaginatedScrollView) -> Int {
        return pages.count
    }

    func paginatedScrollView(paginatedScrollView: PaginatedScrollView, controllerAtIndex index: Int) -> UIViewController {
        return pages[index]
    }
}

PaginatedScrollViewDelegate

UIPageViewController is kind of lame when it comes to knowing exactly when you have switched to the next page or went back to the previous one. That’s the main reason why PaginatedScrollView exists.

protocol PaginatedScrollViewDelegate: class {
    func paginatedScrollView(paginatedScrollView: PaginatedScrollView, didMoveToIndex index: Int)
    func paginatedScrollView(paginatedScrollView: PaginatedScrollView, didMoveFromIndex index: Int)
}

Installation

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

pod 'PaginatedScrollView'

PaginatedScrollView is also available through Carthage. To install
it, simply add the following line to your Cartfile:

github "3lvis/PaginatedScrollView"

License

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

Author

Elvis Nuñez, @3lvis

Latest podspec

{
    "name": "PaginatedScrollView",
    "summary": "Paginated UIScrollView, a simple UIPageViewController alternative written in Swift.",
    "version": "0.2.0",
    "homepage": "https://github.com/3lvis/PaginatedScrollView",
    "license": "MIT",
    "authors": {
        "Elvis Nuu00f1ez": "[email protected]"
    },
    "source": {
        "git": "https://github.com/3lvis/PaginatedScrollView.git",
        "tag": "0.2.0"
    },
    "social_media_url": "https://twitter.com/3lvis",
    "platforms": {
        "ios": "9.0",
        "tvos": "9.0"
    },
    "requires_arc": true,
    "source_files": "Sources/**/*",
    "frameworks": "UIKit",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This