Created
June 24, 2020 07:39
-
-
Save stevencurtis/56b3bc858e66024a0e247cd9576f9eb7 to your computer and use it in GitHub Desktop.
collectionviewcontroller
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 { | |
var collectionView: UICollectionView! | |
var dta = ["a","kldfkaunfd","jello|", "fourth", "5","a","kldfkaunfd","jello|", | |
"fourth", "5", "a","kldfkaunfd","jello|", "fourth", | |
"5","a","kldfkaunfd","jello|", "fourth", "5", | |
"a","kldfkaunfd","jello|", "fourth", "5", "a","kldfkaunfd", | |
"jello|", "fourth", "5"] | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
let layout = UICollectionViewFlowLayout() | |
layout.estimatedItemSize = CGSize(width: 150, height: 150) | |
layout.scrollDirection = .horizontal | |
let frame = self.view.frame | |
collectionView = UICollectionView(frame: frame, collectionViewLayout: layout) | |
collectionView.dataSource = self | |
collectionView.delegate = self | |
let nib = UINib(nibName: "CustomCollectionViewCell", bundle: nil) | |
collectionView.register(nib, forCellWithReuseIdentifier: "cell") | |
self.view.addSubview(collectionView) | |
collectionView.backgroundColor = .lightGray | |
self.view.backgroundColor = .lightGray | |
} | |
} | |
extension ViewController: UICollectionViewDataSource { | |
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { | |
dta.count | |
} | |
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { | |
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! CustomCollectionViewCell | |
cell.txtLab.text = dta[indexPath.row] | |
return cell | |
} | |
} | |
extension ViewController: UICollectionViewDelegate {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment