In image we cleraly see the crousel showing blank image but I want crousel that shows images that bot happening the array of the image are on next slide/page I have added crousel with UICollectionview give the UIcollectionview image size 300/200 it doesn't scroll manually and if we scroll it forcefully it went to first screen and show Blank imageview. NOT showing the crousel Which contain advertisement not Working crousel and UICollectionView
import UIKit
class AdCollectionView: UICollectionViewCell {
@IBOutlet weak var adImage: UIImageView!
}
import UIKit
class Marketplace: UIViewController {
@IBOutlet weak var adCollectionView: UICollectionView!
var Images=["scan","stethscope","pulse","Reorder","specialist","trolley"]
var timer:Timer?
var currentIndex = 0
override func viewDidLoad() {
super.viewDidLoad()
timer = Timer.scheduledTimer(timeInterval:2.0, target: self, selector: #selector(slideToNext), userInfo: nil, repeats: true)
}
@objc func slideToNext(){
if currentIndex < Images.count - 1
{
currentIndex+=currentIndex
adCollectionView.scrollToItem(at: IndexPath(item: currentIndex, section: 0), at: .right, animated: true)
}
else{
currentIndex = 0
}
}
}
extension Marketplace:UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout
{
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return Images.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell=adCollectionView.dequeueReusableCell(withReuseIdentifier:"AdCell", for: indexPath) as! AdCollectionView
cell.adImage.image=UIImage(named: Images[indexPath.row])
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: adCollectionView.frame.width, height: adCollectionView.frame.height)
}
}