UICollectionView 3 column grid, 1px space?? (image included)

前端 未结 4 438
陌清茗
陌清茗 2020-12-31 04:04

I have setup a UICollectionView with a FlowLayout that leaves no space in between cells in either the vertical or horizontal directions.

I have everything working, y

4条回答
  •  孤城傲影
    2020-12-31 04:28

    I was having the same problem, I fixed it with the code below:

     func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
    
        let paddingSpace = sectionInsets.left * 4
        let availableWidth = view.frame.width - paddingspace
        let widthPerItem  = availableWidth/3
    
        return CGSizeMake(width: widthPerItem, height: widthPerItem)
    }
    

    and define the variable below in the begin of your class:

    fileprivate let sectionInsets = UIEdgeInsets(top: 0.0, left: 0.5, bottom: 0.0, right: 0.0)
    

提交回复
热议问题