Git Product home page Git Product logo

mxpagerview's Introduction

MXPagerView

CI Status Version Carthage compatible License Platform

MXPagerView is a pager view with the ability to reuse pages like you would do with a table view and cells. Depending on the transition style, it will load the current page and neighbors and unload others pages.

MXPagerViewController allows you to load pages from storyboard using the MXPageSegue.

Usage

If you want to try it, simply run:

pod try MXPagerView

Or clone the repo and run pod install from the Example directory first.

  • As a UITableView, the MXPagerView calls data source methods to load pages.
#pragma mark <MXPagerViewDataSource>

// Asks the data source to return the number of pages in the pager.
- (NSInteger)numberOfPagesInPagerView:(MXPagerView *)pagerView {
    return 10;
}

// Asks the data source for a view to insert in a particular page of the pager.
- (UIView *)pagerView:(MXPagerView *)pagerView viewForPageAtIndex:(NSInteger)index {
    
    UILabel *label = [UILabel new];
    label.text = [NSString stringWithFormat:@"Page #%i", index];
    [label sizeToFit];

    return label;
}
  • In order to reuse pages, first register the reusable view, e.g:
- (void)viewDidLoad {
    [super viewDidLoad];
    
    //Register UITextView as page
    [self.pagerView registerClass:[UITextView class] forPageReuseIdentifier:@"TextPage"];
}

Then, dequeue a reusable page in the data source:

// Asks the data source for a view to insert in a particular page of the pager.
- (UIView *)pagerView:(MXPagerView *)pagerView viewForPageAtIndex:(NSInteger)index {
    
    //Dequeue reusable page
    UITextView *page = [self.pagerView dequeueReusablePageWithIdentifier:@"TextPage"];
    page.text = @"This is a text";
    
    return page;
}

The MXPagerView comes with a UIView category which exposed the reuse identifier of the page as well as the prepareForReuse method, this is called just before the page is returned from the pager view method dequeueReusablePageWithIdentifier:.

  • Using MXPagerViewController in storyboard is super easy:

Demo

Installation

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

pod "MXPagerView"

Documentation

Documentation is available through CocoaDocs.

Author

Maxime Epain

Twitter

License

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

mxpagerview's People

Contributors

maxep avatar drjid avatar

Watchers

Joeri Djojosoeparto avatar James Cloos 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.