Back to Fspagerview

README

README.md

0.8.311.8 KB
Original Source

<b>SWIFT</b><b>OBJECTIVE-C</b>

FSPagerView is an elegant Screen Slide Library implemented primarily with UICollectionView. It is extremely helpful for making Banner、Product Show、Welcome/Guide Pages、Screen/ViewController Sliders.

Features

  • Infinite scrolling.
  • Automatic Sliding.
  • Horizontal and Vertical paging.
  • Fully customizable item, with predefined banner-style item.
  • Fully customizable page control.
  • Rich build-in 3D transformers.
  • Simple and Delightful api usage.
  • Support SWIFT and OBJECTIVE-C.

Demos

Demo1 - Banner <a id="banner"></a>

Banner

automaticSlidingInterval

The time interval of automatic sliding. 0 means disabling automatic sliding. Default is 0.

e.g.

swift
pagerView.automaticSlidingInterval = 3.0

isInfinite

A boolean value indicates whether the pager view has infinite number of items. Default is false.

e.g.

swift
pagerView.isInfinite = true

decelerationDistance

An unsigned integer value that determines the paging distance of the pager view, which indicates the number of passing items during the deceleration. When the value of this property is FSPagerView.automaticDistance, the actual 'distance' is automatically calculated according to the scrolling speed of the pager view. Default is 1.

e.g.

swift
pagerView.decelerationDistance = 2

itemSize

The item size of the pager view. When the value of this property is FSPagerView.automaticSize, the items fill the entire visible area of the pager view. Default is FSPagerView.automaticSize.

e.g.

swift
pagerView.itemSize = CGSize(width: 200, height: 180)

interitemSpacing

The spacing to use between items in the pager view. Default is 0.

e.g.

swift
pagerView.interitemSpacing = 10

Demo2 - Transformers

Cross Fading
swift
pagerView.transformer = FSPagerViewTransformer(type: .crossFading)

Zoom Out
swift
pagerView.transformer = FSPagerViewTransformer(type: .zoomOut)

Depth
swift
pagerView.transformer = FSPagerViewTransformer(type: .depth)

Linear
swift
pagerView.transformer = FSPagerViewTransformer(type: .linear)

Overlap
swift
pagerView.transformer = FSPagerViewTransformer(type: .overlap)

Ferris Wheel
swift
pagerView.transformer = FSPagerViewTransformer(type: .ferrisWheel)

Inverted Ferris Wheel
swift
pagerView.transformer = FSPagerViewTransformer(type: .invertedFerrisWheel)

Cover Flow
swift
pagerView.transformer = FSPagerViewTransformer(type: .coverFlow)

Cubic
swift
pagerView.transformer = FSPagerViewTransformer(type: .cubic)

Customize your own transformer by subclassingFSPagerViewTransformer.

Demo3 Page Control

Page Control

numberOfPages

The number of page indicators of the page control. Default is 0.

e.g.

swift
pageControl.numberOfPages = 5

currentPage

The current page, highlighted by the page control. Default is 0.

e.g.

swift
pageControl.currentPage = 1

contentHorizontalAlignment

The horizontal alignment of content within the control’s bounds. Default is center.

e.g.

swift
pageControl.contentHorizontalAlignment = .right

setStrokeColor:forState:

Sets the stroke color for page indicators to use for the specified state. (selected/normal).

e.g.

swift
pageControl.setStrokeColor(.green, for: .normal)
pageControl.setStrokeColor(.yellow, for: .selected)

setFillColor:forState:

Sets the fill color for page indicators to use for the specified state. (selected/normal).

e.g.

swift
pageControl.setFillColor(.gray, for: .normal)
pageControl.setFillColor(.white, for: .selected)

setImage:forState:

Sets the image for page indicators to use for the specified state. (selected/normal).

e.g.

swift
pageControl.setImage(UIImage(named:"image1"), for: .normal)
pageControl.setImage(UIImage(named:"image2"), for: .selected)

setPath:forState:

Sets the path for page indicators to use for the specified state. (selected/normal).

e.g.

swift
pageControl.setPath(UIBezierPath(rect: CGRect(x: 0, y: 0, width: 8, height: 8)), for: .normal)
pageControl.setPath(UIBezierPath(ovalIn: CGRect(x: 0, y: 0, width: 8, height: 8)), for: .selected)

Installation

  • Manually
  • Cocoapods
  • Carthage

Manually

  1. Download the source code.
  2. Extract the zip file, simply drag folder Sources into your project.
  3. Make sure Copy items if needed is checked.

Cocoapods

ruby
use_frameworks!
target '<Your Target Name>' do
    pod 'FSPagerView'
end

Carthage

ruby
github "WenchaoD/FSPagerView"

Tutorial

1. Getting started <a id='getting_started'></a>

  • Getting started with code
swift
// Create a pager view
let pagerView = FSPagerView(frame: frame1)
pagerView.dataSource = self
pagerView.delegate = self
pagerView.register(FSPagerViewCell.self, forCellWithReuseIdentifier: "cell")
self.view.addSubview(pagerView)
// Create a page control
let pageControl = FSPageControl(frame: frame2)
self.view.addSubview(pageControl)
  • Getting started with Interface Builder

1、Simply drag UIView instance into your View Controller, Change the Custom Class to FSPagerView. (Or FSPageControl)

2、Link the dataSource and delegate property of FSPagerView to your View Controller.

3、Register a cell class.

swift
@IBOutlet weak var pagerView: FSPagerView! {
    didSet {
        self.pagerView.register(FSPagerViewCell.self, forCellWithReuseIdentifier: "cell")
    }
}

2. Implement FSPagerViewDataSource <a id='implement_fspagerviewdatasource'></a>

swift
public func numberOfItems(in pagerView: FSPagerView) -> Int {
    return numberOfItems
}
    
public func pagerView(_ pagerView: FSPagerView, cellForItemAt index: Int) -> FSPagerViewCell {
    let cell = pagerView.dequeueReusableCell(withReuseIdentifier: "cell", at: index)
    cell.imageView?.image = ...
    cell.textLabel?.text = ...
    return cell
}

3. Implement FSPagerViewDelegate <a id='implement_fspagerviewdelegate'></a>

swift
func pagerView(_ pagerView: FSPagerView, shouldHighlightItemAt index: Int) -> Bool

Asks the delegate if the item should be highlighted during tracking.


swift
func pagerView(_ pagerView: FSPagerView, didHighlightItemAt index: Int)

Tells the delegate that the item at the specified index was highlighted.


swift
func pagerView(_ pagerView: FSPagerView, shouldSelectItemAt index: Int) -> Bool

Asks the delegate if the specified item should be selected.


swift
func pagerView(_ pagerView: FSPagerView, didSelectItemAt index: Int)

Tells the delegate that the item at the specified index was selected.


swift
func pagerView(_ pagerView: FSPagerView, willDisplay cell: FSPagerViewCell, forItemAt index: Int)

Tells the delegate that the specified cell is about to be displayed in the pager view.


swift
func pagerView(_ pagerView: FSPagerView, didEndDisplaying cell: FSPagerViewCell, forItemAt index: Int)

Tells the delegate that the specified cell was removed from the pager view.


swift
func pagerViewWillBeginDragging(_ pagerView: FSPagerView)

Tells the delegate when the pager view is about to start scrolling the content.


swift
func pagerViewWillEndDragging(_ pagerView: FSPagerView, targetIndex: Int)

Tells the delegate when the user finishes scrolling the content.


swift
func pagerViewDidScroll(_ pagerView: FSPagerView)

Tells the delegate when the user scrolls the content view within the receiver.


swift
func pagerViewDidEndScrollAnimation(_ pagerView: FSPagerView)

Tells the delegate when a scrolling animation in the pager view concludes.


swift
func pagerViewDidEndDecelerating(_ pagerView: FSPagerView)

Tells the delegate that the pager view has ended decelerating the scrolling movement.


<a id="support"></a>Support this repo

  • Star this repo <a href="#"></a>

  • Buy me a Coffee. ☕️

    <a href="https://www.paypal.me/WenchaoD" target="_blank"></a>   |   <a href="https://user-images.githubusercontent.com/5186464/45949944-46960480-c030-11e8-9e90-30b015698cf6.png" target="_blank"></a>   |   <a href="https://cloud.githubusercontent.com/assets/5186464/15096872/b06f3a3a-153c-11e6-89f9-2e9c7b88ef42.png" target="_blank"></a>


Author


Documentation