Skip to content

Instantly share code, notes, and snippets.

@JFSene
Created March 6, 2017 01:04
Show Gist options
  • Save JFSene/39d90376adc9938292a8df606afd496e to your computer and use it in GitHub Desktop.
Save JFSene/39d90376adc9938292a8df606afd496e to your computer and use it in GitHub Desktop.
import UIKit
class CollectionViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
@IBOutlet weak var cv: UICollectionView!
let arrayFotos = (1...14).map {
UIImage(named: "\($0).jpg")
}
let cellIdentifier = "CollectionViewCell"
let objects = ["Cat", "Dog", "Fish","Cat", "Dog", "Fish","Cat", "Dog", "Fish","Cat", "Dog", "Fish","Cat", "Dog"]
override func viewDidLoad() {
super.viewDidLoad()
cv.register(UINib(nibName:"CollectionViewCell", bundle: nil), forCellWithReuseIdentifier: cellIdentifier)
cv.backgroundColor = .blue
cv.delegate = self
cv.dataSource = self
}
override func viewWillAppear(_ animated: Bool) {
}
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return objects.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = cv.dequeueReusableCell(withReuseIdentifier: cellIdentifier, for: indexPath) as! CollectionViewCell
cell.backgroundColor = .white
cell.imageView.image = arrayFotos[indexPath.row]
cell.titleLabel.text = objects[indexPath.row]
cell.descriptionLabel.text = "teste"
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let itemSize = view.bounds.width - 36
return CGSize(width: itemSize, height: 200)
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment