Skip to content

Instantly share code, notes, and snippets.

@donguri9
Last active April 12, 2019 21:20
Show Gist options
  • Save donguri9/6694c5a28a343a6df8eade9fa8833e48 to your computer and use it in GitHub Desktop.
Save donguri9/6694c5a28a343a6df8eade9fa8833e48 to your computer and use it in GitHub Desktop.
CollectionView(section)
class ViewController: UIViewController,UICollectionViewDelegate,UICollectionViewDataSource {
override func viewDidLoad() {
super.viewDidLoad()
}
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 2
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if section == 0 {
return 7
} else {
return 2
}
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath)
switch(indexPath.section){
case 0:
cell.backgroundColor = .blue
case 1:
cell.backgroundColor = .red
default:
print("section error")
}
return cell
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment