importUIKit
classHomeViewController:BaseViewController,UICollectionViewDataSource,UICollectionViewDelegate{
staticletreuseIdentifier ="UICollectionViewCell"
varcollectionView:UICollectionView?
overridefuncviewDidLoad() {
super.viewDidLoad()
letlayout =UICollectionViewFlowLayout()
layout.itemSize=CGSize(width:100, height:100)
layout.minimumLineSpacing=10
layout.minimumInteritemSpacing=10
self.collectionView=UICollectionView(frame:CGRect(x:0, y:0, width:ScreenWidth_crx, height:ScreenHeight_crx-64), collectionViewLayout: layout)
self.collectionView?.delegate=self;
self.collectionView?.dataSource=self
self.collectionView?.backgroundColor=UIColor.white
self.view.addSubview(self.collectionView!)
//self.collectionView?.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 50, right: 0)
self.collectionView!.register(UICollectionViewCell.self, forCellWithReuseIdentifier:HomeViewController.reuseIdentifier)
}
//MARK:- UICollectionViewDataSource
funccollectionView(_collectionView:UICollectionView, numberOfItemsInSection section:Int) ->Int{
return20
}
funccollectionView(_collectionView:UICollectionView, cellForItemAt indexPath:IndexPath) ->UICollectionViewCell{
letcell = collectionView.dequeueReusableCell(withReuseIdentifier:HomeViewController.reuseIdentifier, for: indexPath)
cell.backgroundColor=UIColor.red
returncell
}
//MARK:冒号后添加注释说明-添加横线列如下
//FIXME:表示此处有bug或者要优化列如下
//TODO:-今天就先写到这吧睡觉明天继续
//#warning swift2.0中下面发放替换
}
网友评论