@IBOutlet weak var mCollet: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
mCollet.register(UINib(nibName: "CateCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "CateCollectionViewCell")
mCollet.dataSource = self
mCollet.delegate = self
}
- Thiết lập :
extension ViewController : UICollectionViewDataSource, UICollectionViewDelegate,UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 10
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CateCollectionViewCell", for: indexPath ) as! CateCollectionViewCell
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return gridLayout.itemSizeFor(2)
}
}
- Phải có :


Không có nhận xét nào:
Đăng nhận xét