Giter VIP home page Giter VIP logo

djcollectionviewvm's Introduction

DJCollectionViewVM

License MIT Pod version Carthage Compatible Platform info

What

DJCollectionViewVM is a lightweight ViewModel implementation for UICollectionView.

Features

  • less code and more flexible to implement linear layout using UICollectionView with UICollectionViewFlowLayout;
  • dynamic cell and SupplementaryView size caculate;
  • header and footer support like UITableView;
  • prefetch for iOS 7.0+;

Requirements

  • Xcode 7 or higher
  • Apple LLVM compiler
  • iOS 7.0 or higher
  • ARC

Demo

Build and run the DJComponentCollectionViewVM.xcodeproj in Xcode.

Installation

CocoaPods

Edit your Podfile and add DJCollectionViewVM:

pod 'DJCollectionViewVM'

Quickstart

  • Sample code
- (void)testNormal
{
    DJCollectionViewVMCellRegister(self.collectionVM, DJCollectionViewTitleCellRow, DJCollectionViewTitleCell);
    [self.collectionVM removeAllSections];
    
    DJCollectionViewVMSection *contentSection = [DJCollectionViewVMSection sectionWithHeaderHeight:10];
    contentSection.minimumLineSpacing = 10.0f;
    contentSection.minimumInteritemSpacing = 10.0f;
    [self.collectionVM addSection:contentSection];
    for (NSInteger i = 0; i < 100; i ++) {
        DJCollectionViewTitleCellRow *row = [DJCollectionViewTitleCellRow new];
        row.itemSize = CGSizeMake(100, 100);
        row.backgroundColor = [UIColor redColor];
        row.title = [NSString stringWithFormat:@"%@",@(i)];
        [row setSelectionHandler:^(DJCollectionViewVMRow *rowVM) {
            NSLog(@"tap %@",rowVM.indexPath);
        }];
        [contentSection addRow:row];
    }
    
    [self.collectionView reloadData];
}
  • API
Key Classes
DJCollectionViewVM The ViewModel for UICollectionView, which has implemented UICollectionViewDelegate , UICollectionViewDataSource and UICollectionViewDelegateFlowLayout. It has multiple DJCollectionViewVMSection sections.
DJCollectionViewVMSection The ViewModel for sections in DJCollectionViewVM, each section has multiple DJCollectionViewVMRow rows.
DJCollectionViewVMRow The ViewModel for rows in section,it is the root class of all DJCollectionViewVM row hierarchies.
You should subclass DJCollectionViewVMRow to obtain cell characteristics specific to your application's needs. Through DJCollectionViewVMRow, rows inherit a basic interface that communicates with DJCollectionViewVM and DJCollectionViewVMSection.
DJCollectionViewVMCell The View for DJCollectionViewVMRow(ViewModel),it defines the attributes and behavior of the cells that appear in UICollectionView objects. You should subclass DJCollectionViewVMCell to obtain cell characteristics and behavior specific to your application's needs. By default, it is being mapped with DJCollectionViewVMRow.
DJCollectionViewVMReusable The ViewModel for supplementary view in section header and footer,it is the root class of all DJCollectionViewVM supplementary view hierarchies.
You should subclass DJCollectionViewVMReusable to obtain supplementary view characteristics specific to your application's needs. Through DJCollectionViewVMReusable, supplementary views inherit a basic interface that communicates with DJCollectionViewVM and DJCollectionViewVMSection.
DJCollectionViewVMReusableView The View for DJCollectionViewVMReusable(ViewModel),it defines the attributes and behavior of the supplementary views that appear in UICollectionView objects. You should subclass DJCollectionViewVMReusableView to obtain supplementary view characteristics and behavior specific to your application's needs. By default, it is being mapped with DJCollectionViewVMReusable.
  • For exsist cells in your project
    1.If the super class of your cell is UICollectionViewCell ,just change it to DJCollectionViewVMCell.
    2.If tht super class of your cell is your custom class ,you need to implement the protocol DJCollectionViewVMCellDelegate or change it to DJCollectionViewVMCell.

DJTableViewVM

ViewModel for UITableView: DJTableViewVM

Contact

Dokay Dou

License

DJCollectionViewVM is available under the MIT license.

djcollectionviewvm's People

Contributors

dokay avatar

Watchers

 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.