美文网首页
iOS_网格,列表切换

iOS_网格,列表切换

作者: Qy_iOS | 来源:发表于2020-08-17 11:36 被阅读0次

    做法:

    通过改变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;

        }

    }

    相关文章

      网友评论

          本文标题:iOS_网格,列表切换

          本文链接:https://www.haomeiwen.com/subject/veafjktx.html