Last active
April 12, 2019 21:20
-
-
Save donguri9/6694c5a28a343a6df8eade9fa8833e48 to your computer and use it in GitHub Desktop.
CollectionView(section)
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
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