Coder Social home page Coder Social logo

waterflowlayout's Introduction

waterFlowLayout

怎么使用

初始化

  • 初始化数据(从plist加载)

       NSArray *newShops = [Shop objectArrayWithFilename:@"2.plist"];
       [self.shops addObjectsFromArray:newShops];
    
  • 初始化瀑布流控件

      WaterFlowView *waterFlowView = [[WaterFlowView alloc] init];
      self.waterFlowView = waterFlowView;
      waterFlowView.frame = self.view.bounds;
      waterFlowView.delegate = self;
      waterFlowView.dataSouce = self;
      // 跟随父控件的尺寸而自动伸缩
      waterFlowView.autoresizingMask = UIViewAutoresizingFlexibleWidth | 		UIViewAutoresizingFlexibleHeight;
    
  • 加载数据

      // 加载新的数据
      [waterFlowView addHeaderWithTarget:self action:@selector(loadNewShops)];
      // 加载更多数据
      [waterFlowView addFooterWithTarget:self action:@selector(loadMoreShops)];
    

数据源方法

- (NSInteger)numberOfCellInWaterFlowView:(WaterFlowView *)waterFlowView {
return self.shops.count;
}

- (NSUInteger)numberOfColumnsInWaterFlowView:(WaterFlowView *)waterFlowView {
    if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) {
        return  3; //如果是竖屏 返回3列
    } else {
        return 5;
    }
}

- (WaterFlowViewCell *) waterFlowView:(WaterFlowView *)waterFlowView cellAtIndex:(NSUInteger)index {
    
    ShopCell *cell = [[ShopCell alloc] initCellWithWaterFlowView:waterFlowView];
    
    cell.shop = self.shops[index];
    return cell;
  
}

代理方法

- (CGFloat) waterFlowView:(WaterFlowView *)waterFlowView heightAtIndex:(NSUInteger)index {
    Shop *shop = self.shops[index];
    
    //根据cell的宽度 和 图片的宽高比
    return waterFlowView.cellWidth * shop.h / shop.w;
    
}
- (CGFloat) waterFlowView:(WaterFlowView *)waterFlowView marginForType:(WaterFlowViewMarginType)marginType {
    switch (marginType) {
        case WaterFlowViewMarginTypeTop: return 30;
        case WaterFlowViewMarginTypeBottom: return 50;
        case WaterFlowViewMarginTypeLeft: return 10;
        case WaterFlowViewMarginTypeRight: return 10;
       
    
        default: return 5;
           
    }
}
- (void)waterFlowView:(WaterFlowView *)waterFlowView didSelectAtIndex:(NSUInteger)index {
    NSLog(@"点击了第%ld个cell",index);
}

框架采用MJExtension进行数据解析,SDWebImage图像缓存,MJRefresh刷新,

效果图

waterflowlayout'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.