爱意满满的作品展示区。
Elethom

我的第一個 Swift 語言的開源項目終於發佈到 CocoaPods 啦!

  •  
  •   Elethom ·
    Elethom · Jan 27, 2015 · 2835 views
    This topic created in 4162 days ago, the information mentioned may be changed or developed.

    原 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
    

    View on GitHub

    PRSlideView-Swift

    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

    3 replies    2015-01-28 00:01:56 +08:00
    Elethom
        1
    Elethom  
    OP
       Jan 27, 2015
    @Livid
    GitHub Flavored Markdown 的 blockquote 樣式有些奇怪... 左側沒有帶顏色的 padding, 也沒有背景之類的樣式來突出引用.
    yetone
        2
    yetone  
       Jan 27, 2015
    我是熬着夜专门来赞你的
    Elethom
        3
    Elethom  
    OP
       Jan 28, 2015
    @yetone
    感謝! :-)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2422 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 60ms · UTC 10:13 · PVG 18:13 · LAX 03:13 · JFK 06:13
    ♥ Do have faith in what you're doing.