Created
October 19, 2016 10:04
-
-
Save Calvin-Huang/cba2281a512e3dff82810469df62fe7b to your computer and use it in GitHub Desktop.
Implement UICollectionView relatived delegate in class.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout { | |
@IBOutlet var collectionView: UICollectionView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
self.collectionView.dataSource = self | |
self.collectionView.delegate = self | |
} | |
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { | |
return 10 | |
} | |
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { | |
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) | |
cell.backgroundColor = .red | |
return cell | |
} | |
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { | |
return CGSize(width: 50, height: 50) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment