Setting size of UICollectionViewCell in a way that there is no interim spacing in between

前端 未结 4 1807
时光取名叫无心
时光取名叫无心 2021-01-28 23:36

I\'m using an UICollectionView on which I want to place seven cells side by side. The whole screen should be used for this. Currently, I\'m using the width of the c

4条回答
  •  借酒劲吻你
    2021-01-29 00:24

    Step 1: Implement UICollectionViewDelegateFlowLayout(if not done).

    Step 2: Use delegate method of UICollectionViewDelegateFlowLayout.

    func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize
    {
    return CGSizeMake((UIScreen.mainScreen().bounds.width)/7,120); //use height whatever you wants.
    }
    

    Step 3: Go to XIB or StoryBoard where you have your CollectionView.

    Step 4: In XIB or StoryBoard where you have your CollectionView, click on CollectionView.

    Step 5: Go to InterfaceBuilder, then in second last tab (ie: Size Inspector) set Min Spacing

    For Cells = 0

    For Lines = 0

    That it.

提交回复
热议问题