UICollectionView spacing margins

后端 未结 15 970
一向
一向 2020-11-30 16:58

I have a UICollectionView which shows photos. I have created the collectionview using UICollectionViewFlowLayout. It works good but I would like to

相关标签:
15条回答
  • 2020-11-30 17:40

    Setting up insets in Interface Builder like shown in the screenshot below

    Setting section insets for UICollectionView

    Will result in something like this:

    A collection view cell with section insets

    0 讨论(0)
  • 2020-11-30 17:40

    For adding margins to specified cells, you can use this custom flow layout. https://github.com/voyages-sncf-technologies/VSCollectionViewCellInsetFlowLayout/

    extension ViewController : VSCollectionViewDelegateCellInsetFlowLayout 
    {
        func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForItemAt indexPath: IndexPath) -> UIEdgeInsets {
            if indexPath.item == 0 {
                return UIEdgeInsets(top: 0, left: 0, bottom: 10, right: 0)
            }
            return UIEdgeInsets.zero
        }
    }
    
    0 讨论(0)
  • 2020-11-30 17:44
    - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {       
             return UIEdgeInsetsMake(7, 10, 5, 10);    
       }
    
    0 讨论(0)
提交回复
热议问题