Giter Club home page Giter Club logo

viewpager---swift's Introduction

ViewPager---Swift

An easy to use view pager library for iOS in Swift

Installation

Just add ViewPager.swift file to your project, file are present inside ViewPager directory.

Preview

Preview

Setup

The Viewpager follows the Apple convention for data-driven views by providing protocol interfaces ViewPagerDataSource . The ViewPagerDataSource protocol has the following required methods:

func numberOfItems(viewPager:ViewPager) -> Int

Return the number of items (views) in the Viewpager.

func viewAtIndex(viewPager:ViewPager, index:Int, view:UIView?) -> UIView

Return a view to be displayed at the specified index in the ViewPager. The view argument, where views that have previously been displayed in the ViewPager are passed back to the method to be recycled. If this argument is not nil, you can set its properties and return it instead of creating a new view instance, which will slightly improve performance.

func didSelectedItem(index:Int)

Callback when ViewPager clicked, return the number of items (views) in the Viewpager.

Example

ViewController:

override func viewDidLoad() {
    super.viewDidLoad()
    viewPager.dataSource = self;
    // Do any additional setup after loading the view, typically from a nib.
}

extension ViewController :

extension ViewController:ViewPagerDataSource{

func numberOfItems(viewPager:ViewPager) -> Int {
    return 5;
}

func viewAtIndex(viewPager:ViewPager, index:Int, view:UIView?) -> UIView {
    var newView = view;
    var label:UILabel?
    if(newView == nil){
        newView = UIView(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height:  self.view.frame.height))
         newView!.backgroundColor = .randomColor()
        
        label = UILabel(frame: newView!.bounds)
        label!.tag = 1
        label!.autoresizingMask =  [.FlexibleWidth, .FlexibleHeight]
        label!.textAlignment = .Center
        label!.font =  label!.font.fontWithSize(28)
        newView?.addSubview(label!)
    }else{
      label = newView?.viewWithTag(1) as? UILabel
    }
   
    label?.text = "Page View Pager  \(index+1)"
    
    return newView!
}
}

func didSelectedItem(index: Int) {
    print("select index \(index)")
}

License

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

viewpager---swift's People

Contributors

septiyanandika avatar sudargits avatar

Watchers

James Cloos 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.