感谢简友提供的思路 http://www.jianshu.com/p/c59d55609a98
不然一直以为是要在collectionViewCell里面设置灰色边框!
现在直接在vc设item的size为
let kHomeItemW = kScreenW/3 - 5
//行间距,此属性大小决定上下两个cell的间距
layout.minimumLineSpacing = 1
//minimumInteritemSpacing:项间距,此属性设置为0,然后通过控制itemSize的大小来控制左右两个cell的间距
layout.minimumInteritemSpacing = 0
//灰色
collectionView.backgroundColor = RGBA(r: 233, g: 233, b: 233, a: 1)
然后把
collectionViewCell设为白色就可以了!
// MARK:- 初始化 collectionView
lazy var collectionView:UICollectionView = { [unowned self] in
let layout = UICollectionViewFlowLayout()
layout.itemSize = CGSize(width: kHomeItemW, height: kHomeItemH)
//行间距,此属性大小决定上下两个cell的间距
layout.minimumLineSpacing = 1
//minimumInteritemSpacing:项间距,此属性设置为0,然后通过控制itemSize的大小来控制左右两个cell的间距
layout.minimumInteritemSpacing = 0
layout.sectionInset = UIEdgeInsets(top: kItemMargin, left: kItemMargin, bottom: kItemMargin, right: kItemMargin)
// frame 在makeContraints设置
let collectionView = UICollectionView(frame: CGRect.zero, collectionViewLayout: layout)
collectionView.backgroundColor = RGBA(r: 233, g: 233, b: 233, a: 1)
collectionView.register(LotteryHomeCell.self, forCellWithReuseIdentifier: identify)
collectionView.layer.cornerRadius = 5
collectionView.layer.masksToBounds = true
collectionView.isScrollEnabled = false
collectionView.showsHorizontalScrollIndicator = false
collectionView.dataSource = self
collectionView.delegate = self
collectionView.autoresizingMask = [.flexibleHeight, .flexibleWidth]
collectionView.layoutIfNeeded()
return collectionView
}()
网友评论