//UICollectionView商品展示物流。特殊的tableView繼承UIScrollView
//UICollectionView用法與UITableView類似
//collectionViewLayout指定布局瀑布流
//UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:<#(CGRect)#> collectionViewLayout:<#(nonnull UICollectionViewLayout *)#>];
//創(chuàng)建一個(gè)布局
UICollectionViewFlowLayout *lagout = [[UICollectionViewFlowLayout alloc] init];
//行間距
lagout.minimumLineSpacing= 10;
//組間距,item之間的間距
lagout.minimumInteritemSpacing= 10;
//大小
[lagout setItemSize:CGSizeMake(100, 100)];
//UICollectionViewScrollDirectionHorizontal橫向的
//UICollectionViewScrollDirectionVertical縱向的
lagout.scrollDirection=UICollectionViewScrollDirectionVertical;
//區(qū)內(nèi)邊距
lagout.sectionInset=UIEdgeInsetsMake(20, 20, 20, 20);
//創(chuàng)建UICollectionView對(duì)象指定布局
UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:self.view.bound scollectionViewLayout:lagout];
//分頁(yè)顯示
collectionView.pagingEnabled = YES;
//設(shè)置數(shù)據(jù)源和代理
collectionView.delegate=self;
collectionView.dataSource=self;
//注冊(cè)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];
//隨機(jī)顏色驹饺,導(dǎo)入自定的擴(kuò)展類UIColor+Hex.h
cell.backgroundColor= [UIColor colorWithHexString:@"#2653ab"];
return cell;
}