Sapporo, Cellmodel驱动的泛型管理器

分享于 

6分钟阅读

GitHub

  繁體 雙語
Cellmodel-driven collectionview manager
  • 源代码名称:Sapporo
  • 源代码网址:http://www.github.com/nghialv/Sapporo
  • Sapporo源代码文档
  • Sapporo源代码下载
  • Git URL:
    git://www.github.com/nghialv/Sapporo.git
    Git Clone代码到本地:
    git clone http://www.github.com/nghialv/Sapporo
    Subversion代码到本地:
    $ svn co --depth empty http://www.github.com/nghialv/Sapporo
    Checked out revision 1.
    $ cd repo
    $ svn up trunk
    
    Sapporo

    LanguageCocoaPods [ Carthage compatible ] ( https://github.com/Carthage/Carthage ) LicenseIssues

    cellmodel驱动的泛型管理器

    特性

    • 轻松管理你的节和单元格 (reset/insert/append/remove/update)
    • 不需要为 UICollectionViewDelegateUICollectionViewDataSource 协议编写代码
    • 不需要关心单元格标识符
    • 通过尾随闭合处理单元格选择
    • 支持方法链接
    • 支持下标
    • 完整示例
    快速示例
    // viewController swift filelet sapporo =Sapporo(collectionView: self.collectionView)
     let cellmodel =YourCellModel(title: "Title", des: "description") {
     println("Did select cell with title = (title)")
     }
     let topSection =SASection()
     sapporo
    . reset(topSection)
    . bump()
     topSection
    . append(cellmodel) // append a new cell model in datasource. bump() // show the new cell in the collection view topSection
    . remove(1...3)
    . bump()
     topSection
    . move(fromIndex: 0, toIndex: 3)
    . bump()
    // your cell swift fileclassYourCellModel : SACellModel {
     let title:Stringlet des:Stringinit(title: String, des: String, selectionHandler: SASelectionHandler) {
     self.title= title
     self.des= des
     super.init(cellType: YourCell.self, selectionHandler: selectionHandler)
     }
     }
     classYourCell : SACell, SACellType {
     typealiasCellModel= YourCellModel
     @IBOutletweakvar titleLabel: UILabel!overridefuncconfigure() {
     super.configure()
     guardlet cellmodel = cellmodel else {
     return }
     titleLabel.text= cellmodel.title }
     }

    用法

    • 处理部分
    // retrieve a section or create a new section if it doesn't already existlet section = sapporo[0]
     // inserting sapporo.insert(section, atIndex: 1)
    . bump()
     // moving sapporo.move(fromIndex: 1, toIndex: 5)
    . bump()
     // removing sapporo.remove(index)
    . bump()
     sapporo.reset() // remove all data. bump()
     // handing section index by enumenumSection : Int, SectionIndex {
     caseTop=0caseCentercaseBottomvar intValue:Int {
     returnself.rawValue }
     }
     let topSection = sapporo[Section.Top]
    • 处理单元格
    // appending sapporo[0]
    . append(cellmodel) // append a cellmodel. bump() // and bump to show the cell in the collection view sapporo[TopSection]
    . append(cellmodels) // append a list of cellmodels. bump() 
     // by using sectionlet section = sapporo[Section.Top]
     section
    . append(cellmodel)
    . bump()
     // 2. inserting section
    . insert(cellmodels, atIndex: 1)
    . bump()
     section
    . insertBeforeLast(cellmodels)
    . bump()
     // 3. reseting section
    . reset(cellmodels) // replace current data in section by the new data. bump()
     section
    . reset() // or remove all data in section. bump()
     // 4. moving section
    . move(fromIndex: 5, toIndex: 1)
    . bump()
     // 5. removing section
    . remove(1)
    . bump()
     section
    . remove(cellmodel)
    . bump()
     section
    . remove(2...5)
    . bump()
     section
    . removeLast()
    . bump()
     // updating celllet cellmodel = section[1]
     cellmodel.property= newData
     cellmodel.bump()
     // able to retrieve a cellmodel by indexpathlet cellmodel = sapporo[indexpath]
    • 注册单元格,页眉,页脚,可以重用视图
     sapporo
    . registerCellByNib(CustomCell)
    . registerCell(SimpleCell)
    . registerSupplementaryViewByNib(HeaderView.self, kind: "SectionHeader")
    • 自定义布局

    如果希望自定义集合视图的布局,只需创建SALayout的子类并调用 setLayout 方法来设置新的布局实例。

    classCustomLayout: SALayout {
     // the implementation for your layout }
     let layout =CustomLayout()
     sapporo.setLayout(layout)

    演示应用

    使用 Sapporo 时,你是否担心定制性? 这是你的答案,一个使用 Sapporo 实现的日历应用。

    安装

    • 使用 Carthage

      • 将 github nghialv/Sapporo 插入你的Cartfile
      • 运行 carthage update
    • 使用 CocoaPods

      • 将下列内容插入你的Podfile
      
       use_frameworks!
      
      
      
       target 'YOUR_TARGET_NAME' do
      
      
       pod 'Sapporo'
      
      
       end
      
      
      
      
      • 运行 pod install
    • 使用子模块

    要求

    • iOS 8.0 +
    • Xcode 8 +
    • Swift 3

    许可证

    Sapporo是在 MIT许可协议下发布的。


    MAN  COL  Drive  Collect  collection  单元格  
    相关文章