CollectionView

// UICollectionView :集合视图.可布局出来各种展示效果,可支持多列展示数据,支持两个方向滚动(或)

    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];

    //每个item的大小

    layout.itemSize = CGSizeMake(100, 100);

//2.设置分区的缩进量  上, 左, 下,右,

    layout.sectionInset = UIEdgeInsetsMake(5, 10, 5, 5);

    //3.设置最小item间距

    layout.minimumInteritemSpacing = 10;

    //4.设置最小的行间距

    layout.minimumLineSpacing = 20;

    //5.设置滑动方向

//     layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;//水平方向

    //6.设置页眉的高度

    layout.headerReferenceSize = CGSizeMake(100, 200);

    layout.footerReferenceSize = CGSizeMake(100, 200);

    //创建

    UICollectionView *collectionView = [[UICollectionView alloc]initWithFrame:[UIScreen mainScreen].boundscollectionViewLayout:layout];

    //配置属性

    collectionView.dataSource = self;

    //注册cell

    [collectionView registerClass:[CollectionViewCell class] forCellWithReuseIdentifier:@"item"];

    //注册页眉

    [collectionView registerClass:[HeaderView class]forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header"];

     //注册页脚

    [collectionView registerClass:[UICollectionReusableView class]forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footer"];

    //代理

    collectionView.delegate = self;

        //加载到根视图

    [self.view addSubview:collectionView];

 

posted @ 2016-10-29 14:18  Comder  阅读(136)  评论(0编辑  收藏  举报