Coder Social home page Coder Social logo

imagelayout's Introduction

ImageLayout

瀑布流,网络图片瀑布流

GitHub: https://github.com/Zws-China/ImageLayout

PhotoShoot

image image image image image

How To Use

#import "WSLayout.h"

@property (strong, nonatomic) UICollectionView *collectionView;
@property (strong, nonatomic) WSLayout *wslayout;


self.wslayout = [[WSLayout alloc] init];
self.wslayout.lineNumber = 2; //列数
self.wslayout.rowSpacing = 5; //行间距
self.wslayout.lineSpacing = 5; //列间距
self.wslayout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5); //内边距


// 透明时用这个属性(保证collectionView 不会被遮挡, 也不会向下移)
//self.edgesForExtendedLayout = UIRectEdgeNone;
// 不透明时用这个属性
//self.extendedLayoutIncludesOpaqueBars = YES;
self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height-64) collectionViewLayout:self.wslayout];

[self.collectionView registerClass:[WSCollectionCell class] forCellWithReuseIdentifier:@"collectionCell"];
self.collectionView.dataSource = self;
self.collectionView.delegate = self;
self.collectionView.backgroundColor = [UIColor lightGrayColor];
[self.view addSubview:self.collectionView];


//返回每个cell的高   对应indexPath
[self.wslayout computeIndexCellHeightWithWidthBlock:^CGFloat(NSIndexPath *indexPath, CGFloat width) {

    CellModel *model = modelArray[indexPath.row];
    CGFloat oldWidth = model.imgWidth;
    CGFloat oldHeight = model.imgHeight;

    CGFloat newWidth = width;
    CGFloat newHeigth = oldHeight*newWidth / oldWidth;
    return newHeigth;
}];


#pragma mark - UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {

    return modelArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

    WSCollectionCell *cell = (WSCollectionCell *)[self.collectionView dequeueReusableCellWithReuseIdentifier:@"collectionCell" forIndexPath:indexPath];

    cell.model = modelArray[indexPath.row];

    return cell;
}


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