Coder Social home page Coder Social logo

productinfo / paginatedscrollview Goto Github PK

View Code? Open in Web Editor NEW

This project forked from 3lvis/paginatedscrollview

0.0 3.0 0.0 204 KB

Paginated UIScrollView, a simple UIPageViewController alternative written in Swift.

License: Other

Swift 90.07% Ruby 8.11% Objective-C 1.82%

paginatedscrollview's Introduction

PaginatedScrollView

Version Carthage compatible platforms License

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

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

paginatedscrollview's People

Contributors

3lvis avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.