UICollectionView spacing margins

后端 未结 15 1033
一向
一向 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:27

    In swift 4 and autoLayout, you can use sectionInset like this:

    let layout = UICollectionViewFlowLayout()
            layout.scrollDirection = .vertical
            layout.itemSize = CGSize(width: (view.frame.width-40)/2, height: (view.frame.width40)/2) // item size
            layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10) // here you can add space to 4 side of item
            collectionView = UICollectionView(frame: self.view.bounds, collectionViewLayout: layout) // set layout to item
            collectionView?.register(ProductCategoryCell.self, forCellWithReuseIdentifier: cellIdentifier) // registerCell
            collectionView?.backgroundColor = .white // background color of UICollectionView
            view.addSubview(collectionView!) // add UICollectionView to view
    

提交回复
热议问题