从 UICollectionView 中删除所有单元格 space

Remove all cell space from UICollectionView

小猪放弃了这个 SO ,

如果我改变

 cell.layer.borderWidth = 0.0

它会删除单元格顶部和底部的边框,但不会删除左右边框。 http://imgur.com/c2oDzjc 是否有去除所有边框和单元格间距以使图像完全齐平的方法?我的代码:

var collectionView: UICollectionView?
var screenSize: CGRect!
var screenWidth: CGFloat!
var screenHeight: CGFloat!

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    screenSize = UIScreen.mainScreen().bounds
    screenWidth = screenSize.width
    screenHeight = screenSize.height

    let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
    layout.minimumInteritemSpacing = 0
    layout.minimumLineSpacing = 0

}

func collectionView(collectionView: UICollectionView,
    cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

    let cell: CollViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("cellIdentifier", forIndexPath: indexPath) as! CollViewCell
    //cell.imageCell.image = UIImage(named: self.gridIMages[indexPath.row])

    cell.backgroundColor = UIColor.whiteColor()
    cell.layer.borderColor = UIColor.blackColor().CGColor
    cell.layer.borderWidth = 0.0
    cell.frame.size.width = screenWidth / 3
    cell.frame.size.height = screenHeight / 3

    return cell
}

您没有在任何地方指定布局。您只是创建它而不使用它。

因此 viewDidLoad 中需要 collectionView.collectionViewLayout = layout。但是在界面生成器中设置它可能更容易。