10000 GitHub - SeptiyanAndika/ViewPager---Swift: Simple View Pager library for Swift
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on May 12, 2020. It is now read-only.

SeptiyanAndika/ViewPager---Swift

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Simple View Pager library for Swift

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages

0