I have an array called imageArray = ["one", "two", ... "eight"]. And it fills a collection view with images. Preconditions: The cell is centered in the view and pretty much takes up the majority of the collectionview/view. The image view is on top and is just a little smaller than the cell. Ok so now I need to count which image the user is on. So if the user scrolls to image 3 I need a way to count 3. I am new to ios programming when it comes to collection views, just found out about them, and need some help. Here is some code (basic setup)
class ViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {
@IBOutlet weak var myCollectionView: UICollectionView!
@IBOutlet var mainView: UIView!
var imageArray = ["one", "two", "three", "four", "five", "six", "seven", "eight"]
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return imageArray.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! UserFeedCollectionViewCell
cell.myImage.image = UIImage(named: imageArray[indexPath.row])
cell.myImage.layer.cornerRadius = 12.0
cell.myImage.clipsToBounds = true
return cell
}