GithubHelp home page GithubHelp logo

sjjwaterfallview's Introduction

SJJWaterFallView

利用collectionView,最简单的方式实现瀑布流功能

1,引入自定义的JWatterLayout.h,JJCollectionViewCell.h的头文件

2,创建一个JWatterLayout的对象self.waterLayout(也可以不使用懒加载);

  • (JWatterLayout *)waterLayout { if (_waterLayout == nil) {

      _waterLayout = [[JWatterLayout alloc] init];
      _waterLayout.dataSource    = self;
      _waterLayout.sectionInset = UIEdgeInsetsMake(20, 10, 10, 10);
      _waterLayout.lineNumber = 2;
      _waterLayout.rowSpacing = 10.0f;
      _waterLayout.lineSpacing = 10.0f;
    

    } return _waterLayout; }

3,利用self.waterLayout创建一个collectionView的对象self.collectionView(也可以不使用懒加载);

  • (UICollectionView *)collectionView { if (_collectionView == nil) { _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height) collectionViewLayout:self.waterLayout]; _collectionView.backgroundColor = [UIColor cyanColor]; [_collectionView registerClass:[JJCollectionViewCell class] forCellWithReuseIdentifier:kIdentifierCell]; _collectionView.dataSource = self; } return _collectionView; }

4.实现你需要collectionView代理;

5.实现self.waterLayout的dataSource,返回返回每个cell的高度(高度按情况返回)

  • (CGFloat)itemHeightWithIndexPath:(NSIndexPath *)indexPath itemWidth:(CGFloat)width { //返回每个cell的高度 if(indexPath.row%3 == 0) { return 200; } else if(indexPath.row%3 == 1) { return 150; }else { return 230; } }

6.详情看demo

sjjwaterfallview's People

Contributors

jacksujunjie avatar

Stargazers

 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.