iOS_网格,列表切换

做法:

通过改变UIcollectionviewFlowLayout 布局,完成切换


// 列表和网格切换

-(void)switchGoodsListType{

    if (isPermutation) {        // collectionview 样式

        isPermutation = NO;

        _flowLayout.itemSize=CGSizeMake(171*unitPX,275*unitPX);

        _flowLayout.minimumLineSpacing=10*unitPX;        // 行间距

        _flowLayout.minimumInteritemSpacing = 10*unitPX;    // 列间距

        _flowLayout.sectionInset = UIEdgeInsetsMake(10*unitPX, 10*unitPX, 10*unitPX, 10*unitPX); // 上左下右

        _goodsListCollectionView.collectionViewLayout = _flowLayout;


    }else{    // tableview 样式

        isPermutation = YES;

        _flowLayout.itemSize=CGSizeMake(SCREEN_WIDTH,130*unitPX);

        _flowLayout.minimumLineSpacing      =0;

        _flowLayout.minimumInteritemSpacing = 0;

        _flowLayout.sectionInset = UIEdgeInsetsMake(10, 0, 10, 0);

        _goodsListCollectionView.collectionViewLayout = _flowLayout;

    }

    [_goodsListCollectionView reloadData];

}



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


    if (isPermutation) {

        PHGoodsTableListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:__goodsListTableCell forIndexPath:indexPath];

        cell.backgroundColor = [UIColor whiteColor];

        returncell;

    }else{

        PHGoodsListCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:__goodsListCollectionCell forIndexPath:indexPath];

        cell.backgroundColor = [UIColor whiteColor];

        returncell;

    }

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。