Hi so my code is not working and I want to implement a few new things in to the code these things are to be placed in the order they are displayed in this post although I´m posting them as ´´//`´in the post. What im trying to to is an automatic UIView which is also able to respond to interactions such as a drag. Hopefully the code will explain easier what im trying to achieve here.
import UIKit
class ViewController: UIViewController {
@IBOutlet var collectioView: UICollectionView!
@IBOutlet var myPage: UIPageControl!
var SliderImages:[String]=["3","",""]
// var SliderImages = [UIImage(named: "2")!, UIImage(named: "2")!, UIImage(named: "2")!]
// var timer : Timer?
// var currentCellIndex = 0
// var currentPage:Int=0
override func viewDidLoad() {
super.viewDidLoad()
collectioView.delegate = self
collectioView.dataSource = self
// pageControl.numberOfPages = SliderImages.count
myPage.currentPage=0
myPage.numberOfPages=SliderImages.count
// startTimer()
}
// func startTimer(){ timer = Timer.scheduledTimer(timeInterval: 2.5, target: self, selector: #selector(moveToNextIndex), userinfo: nil, repeats: true)
}
// @objc func moveToNextIndex(){ if currentCellIndex < SliderImages.count -1{ currentCellIndex += 1
// } else { currentCellIndex = 0
// } currentCellIndex += 1 collectionView.scrollToItem(at: IndexPath(item: curentCellIndex, section: 0), at: .centeredHorizontally, animated: true)
// pageControl.currentPage = currentCellIndex
extension ViewController : UICollectionViewDataSource , UICollectionViewDelegate {
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int{
return SliderImages.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! MyCollectionCell
cell.myWebImage.image=UIImage(named: SliderImages[indexPath.row])
return cell
}
func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
myPage.currentPage=indexPath.row
// func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSIZE { return CGSize(width: collectionView.frame.width, height: collectionView.frame.height.
}
// func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat { return 0
}
So I’ve run this code and it’s obviously wrong and of course while it says what’´s wrong I don’t really know how to fix this. Thanks for any kind of response!