原 po: 我的第一個 Swift 開源庫 PRSlideView-Swift
今天清理了一下磁盤, 更新到 beta 版本的 CocoaPods, 將寫好的項目發佈到 CocoaPods 上去了. \w/
在 CocoaPods 發佈 Swift 項目需要將 Command Line Tools 更新到最新版本:
$ xcode-select --install
更新 CocoaPods 到最新的測試版:
$ gem install cocoapods --pre
在國內使用淘寶源的朋友需要切換到官方源:
$ gem sources -r http://ruby.taobao.org/
$ gem sources -r https://ruby.taobao.org/
$ gem sources -a https://rubygems.org/
由于淘宝镜像这边没有实现 /api 下面的协议,而安装 pre 版本需要这些东西检查依赖,所以如果你需要这类安装需求的时候,请临时切换回官方的 RubyGems 源。
最後發佈 pod:
$ pod trunk push
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.
In your Podfile
:
pod 'PRSlideView-Swift'
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:
:-)
1
Elethom OP @Livid
GitHub Flavored Markdown 的 blockquote 樣式有些奇怪... 左側沒有帶顏色的 padding, 也沒有背景之類的樣式來突出引用. |
2
yetone 2015-01-27 23:42:09 +08:00
我是熬着夜专门来赞你的
|