//UICollectionView商品展示物流。特殊的tableView继承UIScrollView
//UICollectionView用法与UITableView类似
//collectionViewLayout指定布局瀑布流
//UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:<#(CGRect)#> collectionViewLayout:<#(nonnull UICollectionViewLayout *)#>];
//创建一个布局
UICollectionViewFlowLayout *lagout = [[UICollectionViewFlowLayout alloc] init];
//行间距
lagout.minimumLineSpacing= 10;
//组间距,item之间的间距
lagout.minimumInteritemSpacing= 10;
//大小
[lagout setItemSize:CGSizeMake(100, 100)];
//UICollectionViewScrollDirectionHorizontal横向的
//UICollectionViewScrollDirectionVertical纵向的
lagout.scrollDirection=UICollectionViewScrollDirectionVertical;
//区内边距
lagout.sectionInset=UIEdgeInsetsMake(20, 20, 20, 20);
//创建UICollectionView对象指定布局
UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:self.view.bound scollectionViewLayout:lagout];
//分页显示
collectionView.pagingEnabled = YES;
//设置数据源和代理
collectionView.delegate=self;
collectionView.dataSource=self;
//注册cell
[collectionViewregisterClass:[UICollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([UICollectionViewCell class])];
[self.view addSubview:collectionView];
}
#pragma mark --- UICollectionViewDataSource, UICollectionViewDelegate
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return100;
}
-(UICollectionViewCell *)collectionView:(UICollectionView*)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([UICollectionViewCell class]) forIndexPath:indexPath];
//随机颜色,导入自定的扩展类UIColor+Hex.h
cell.backgroundColor= [UIColor colorWithHexString:@"#2653ab"];
return cell;
}