Latest 0.2.2b
Homepage https://github.com/Elethom/PRSlideView-Swift
License MIT
Platforms ios 7, requires ARC
Authors

Cocoapods

This is the Swift language version of PRSlideView.

General

Slide view with gracefully written UIKit-like methods, delegate and data source protocol. Infinite scrolling supported.

Note: Auto layout not supported due to the special behaviours of UIScrollView. Please use autoresizing mask instead or wrap it with a container view.

Installation

With CocoaPods

In your Podfile:

pod 'PRSlideView-Swift'

Usage

Configure a Slide View

slideView.delegate = self
slideView.dataSource = self
slideView.scrollDirection = .Vertical
slideView.infiniteScrollingEnabled = true
slideView.registerClass(
    PRAlbumPage.self,
    identifier: PRAlbumPage.description()
)

Create a Slide View Page Subclass

import UIKit

public class PRAlbumPage: PRSlideViewPage {
    public private(set) var coverImageView: UIImageView

    required public init(frame: CGRect, identifier: String) {
        self.coverImageView = UIImageView()

        super.init(frame: frame, identifier: identifier)

        let coverImageView = self.coverImageView
        coverImageView.frame = self.bounds
        coverImageView.autoresizingMask = (.FlexibleWidth | .FlexibleHeight)
        coverImageView.contentMode = .ScaleAspectFit
        self.addSubview(coverImageView)
    }

    required public init(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

Use Data Source

// MARK: PRSlideViewDataSource

func numberOfPagesInSlideView(slideView: PRSlideView) -> Int {
    return self.albumData.count
}

func slideView(slideView: PRSlideView, pageAtIndex index: Int) -> PRSlideViewPage {
    let page: PRAlbumPage = slideView.dequeueReusablePageWithIdentifier(PRAlbumPage.description(), index: index) as PRAlbumPage

    let imageName: String = self.albumData[index].stringByAppendingPathExtension("jpg")!
    page.coverImageView.image = UIImage(named: imageName)

    return page
}

Use Delegate

// MARK: PRSlideViewDelegate

func slideView(slideView: PRSlideView, didScrollToPageAtIndex index: Int) {
    self.titleLabel.text = self.albumData[index]
}

func slideView(slideView: PRSlideView, didClickPageAtIndex index: Int) {
    let alertView: UIAlertView = UIAlertView(
        title: "You clicked on an album",
        message: "Title: (self.albumData[index])",
        delegate: nil,
        cancelButtonTitle: "OK")
    alertView.show()
}

All done! You can check out the code in the demo provided.

License

This code is distributed under the terms and conditions of the MIT license.

Donate

You can support me by:

:-)

Contact

Latest podspec

{
    "name": "PRSlideView-Swift",
    "version": "0.2.2b",
    "summary": "Slide view with UIKit-like methods, delegate and data source protocol.",
    "homepage": "https://github.com/Elethom/PRSlideView-Swift",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Elethom Hunter": "[email protected]"
    },
    "social_media_url": "https://twitter.com/ElethomHunter",
    "platforms": {
        "ios": 7
    },
    "source": {
        "git": "https://github.com/Elethom/PRSlideView-Swift.git",
        "tag": "0.2.2b"
    },
    "source_files": "Classes/*.swift",
    "requires_arc": true
}

Pin It on Pinterest

Share This