Giter Club home page Giter Club logo

collectionviewtools's Introduction

CollectionViewTools

Platform Swift Version Carthage Compatible CocoaPods Compatible SPM Compatible PRs Welcome

Effective framework, similar to TableViewTools for making your UICollectionView usage simple and comfortable. It allows you to move UICollectionView configuration and interaction logic to separated objects and simply register, add and remove cells from the collection view.

Features

  • Separate layer that synchronizes data with the cell appearance
  • Full implementation of UICollectionViewDelegate and UICollectionViewDataSource under the hood
  • Support of protocols and subclasses as data models
  • No type casts and switches required

Requirements

  • iOS 8.0+
  • Xcode 8.0+

Installation

Carthage

Create a Cartfile that lists the framework and run carthage update. Follow the instructions to add the framework to your project.

github "rosberry/CollectionViewTools"

CocoaPods

You can use CocoaPods to install Product Name by adding it to your Podfile:

platform :ios, '8.0'
use_frameworks!
pod 'CollectionViewTools'

Manually

Drag Sources folder from last release into your project.

Usage

Creating manager

manager = CollectionViewManager(collectionView: collectionView)

Creating section

let titles = ["Item 1", "Item 2", "Item 3"]
var cellItems = [ExampleCollectionViewCellItem]()
titles.forEach { title in
let cellItem = ExampleCollectionViewCellItem(title: title)
    cellItems.append(cellItem)
}

let sectionItem = CollectionViewSectionItem(cellItems: cellItems)
manager.sectionItems = [sectionItem]

Cell item implementation

class ExampleCollectionViewCellItem: CollectionViewCellItemProtocol {
    
    private let title: String
    
    var reuseType = ReuseType(cellClass: ExampleCollectionViewCell.self)
    
    init(title: String) {
        self.title = title
    }
    
    func size(for collectionView: UICollectionView, at indexPath: IndexPath) -> CGSize {
        return CGSize(width: 100, height: 40)
    }
    
    func cell(for collectionView: UICollectionView, at indexPath: IndexPath) -> UICollectionViewCell {
        let cell: ExampleCollectionViewCell = collectionView.dequeueReusableCell(for: indexPath)
        cell.titleLabel.text = title
        return cell
    }
    
    func size(for collectionView: UICollectionView, with layout: UICollectionViewLayout, at indexPath: IndexPath) -> CGSize {
        return size(for: collectionView, at: indexPath)
    }
}

Authors

About

This project is owned and maintained by Rosberry. We build mobile apps for users worldwide ๐ŸŒ.

Check out our open source projects, read our blog or give us a high-five on ๐Ÿฆ @rosberryapps.

License

Product Name is available under the MIT license. See the LICENSE file for more info.

collectionviewtools's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.