Placing a margin around each edge of the UICollectionView

后端 未结 7 1645
天涯浪人
天涯浪人 2020-12-14 18:18

When the UICollectionView is populated with items they always go right to the edges of the UICollectionView like so:

---------------
|X X X X X X X|
|X X X X         


        
7条回答
  •  再見小時候
    2020-12-14 18:57

    You can pretty much control every aspect of the grid with collectionview's protocol. Here's an example:

    - (UICollectionViewFlowLayout *)collectionViewFlowLayout
    {
        UICollectionViewFlowLayout *flowLayout = [UICollectionViewFlowLayout new];
        flowLayout.itemSize = CGSizeMake(180, 255);
        flowLayout.sectionInset = UIEdgeInsetsMake(10, 30, 0, 30);
        flowLayout.minimumInteritemSpacing = 0.0f;
        flowLayout.minimumLineSpacing = 0.0f;
        flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
        return flowLayout;
    }
    

    The one you would want to change in your case is the sectionInsets

提交回复
热议问题