Swift-瀑布流


import UIKit

class SecondController: BaseViewController ,UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout{

var myCollectionView : UICollectionView?

override func viewDidLoad() {

super.viewDidLoad()

self.view.backgroundColor = UIColor.yellow

let myViewLayout = UICollectionViewFlowLayout.init()

myCollectionView = UICollectionView.init(frame: CGRect.init(x: 0, y: 64, width: SCREEN_W, height: SCREEN_H - 64 - 50), collectionViewLayout: myViewLayout)

myCollectionView?.dataSource = self

myCollectionView?.delegate = self

myCollectionView?.register(UICollectionViewCell.classForCoder(), forCellWithReuseIdentifier: "cell")

self.view.addSubview(myCollectionView!)

self.navigationController?.navigationBar.barTintColor = UIColor.yellow

}

func numberOfSections(in collectionView: UICollectionView) -> Int {

return 10

}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {

return 3

}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)

cell.backgroundColor = UIColor.red

return cell

}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {

let sets = UIEdgeInsets.init(top: 0, left:10, bottom:10, right:10)

return sets

}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

let size = CGSize.init(width: (SCREEN_W-50)/3, height: (SCREEN_W-50)/3)

return size

}

override func didReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

// Dispose of any resources that can be recreated.

}

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容