TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Jan 2015 |
SPMSupports SPM | ✗ |
Maintained by Elethom Hunter.
This is the Swift language version of PRSlideView.
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.
slideView.delegate = self
slideView.dataSource = self
slideView.scrollDirection = .Vertical
slideView.infiniteScrollingEnabled = true
slideView.registerClass(
PRAlbumPage.self,
identifier: PRAlbumPage.description()
)
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")
}
}
// 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
}
// 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.
This code is distributed under the terms and conditions of the MIT license.
You can support me by:
:-)