UICollectionView

UICollectionViewUITableView的升级版本,对于UITableView来说   系统提供的cell上存在一些显示内容,但是UICollectionViewcell干干净净,因此UICollectionView想显示内容必须使用自定义Cell.UITableView只支持单列竖直滚动,UICollectionView可以支持多列并且可以控制滚动方向.

//UICollectionViewDelegateFlowLayout

//注意:在使用系统提供的布局时,不用设置该协议的代理人,默认直接设置delegateDataSource


   //创建网格化布局
    UICollectionViewFlowLayout *flowLayout = [[[UICollectionViewFlowLayout alloc]init]autorelease];

使用瀑布流比较好用,不过这个样式类是创建UICollectionView必备的.
    //修改背景颜色(默认背景颜色黑色)
    self.collectionView.backgroundColor = [UIColor whiteColor];
    //设置cell的尺寸(由布局完成)
    flowLayout.itemSize = CGSizeMake((self.view.frame.size.width-30)/2, 100);
如果是瀑布流的话注意是itemWidth

    //设置每个分区的边框范围
  
    flowLayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);


//设置最小列间距,最小行间距 这个是最小的哦,如果间距比minimum大,就按间距来,如果间距比minimum小,就按minimum的值.
    flowLayout.minimumInteritemSpacing = 5;
    flowLayout.minimumLineSpacing = 10;

set = UIEdgeInsetsMake(10, 10, 10, 10);




//专门返回每个分区的页眉或者是页脚

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath

{

    if (kind == UICollectionElementKindSectionHeader) {

        HeaderCollectionReusableView *header = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"header" forIndexPath:indexPath];

        header.textLabel.text = @"萌娃";

        return header;

    }

    else

    {

        return nil;

    }

}



你可能感兴趣的:(UICollectionView)