func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let width = (ScreenW - 17*4) / 3
return CGSize(width: width, height: 58 )
}
ps:17 = 16 + 1,如下
let layout = UICollectionViewFlowLayout.init()
// 设置item的排列方式 ( horizontal , vertical)
layout.scrollDirection = .vertical
// 设置item的size
// layout.itemSize = CGSize(width: self.view.frame.size.width/4, height: self.view.frame.size.width/4)
// 列间距
layout.minimumLineSpacing = 16
// 行间距
layout.minimumInteritemSpacing = 16
// 设置item的四边边距
layout.sectionInset = UIEdgeInsets(top: 16, left: 16, bottom: 16, right: 16)
// 初始化
let collectview = UICollectionView.init(frame: CGRectZero, collectionViewLayout: layout)
collectview.backgroundColor = Color_Background_Base
// 设置代理对象
collectview.delegate = self
// 设置数据源对象
collectview.dataSource = self
self.collectview = collectview
// 注册Cell
collectview.register(MineGoldCollectionViewCell.self, forCellWithReuseIdentifier: "MineGoldCollectionViewCell")
view.addSubview(collectview)
网友评论