Use the ImageSlideShow module to implement the sliding images.
pod 'ImageSlideshow', '~> 1.9.0'
To know more about how to install CocoaPods, refer this link.
2. In Main.storyboard, create a UIView. This is where you will place the SlideShow.
3. Assign the UIView created in Step2 to Class “ImageSlideshow”
3. Link the UIView created in Step 3 to an IBOutlet in the ViewController.
4. In ViewController, paste the below code.
Note : You need to update the code with your own image asset names
//
// ViewController.swift
// Sliding Images
//
// Created by Animesh Banerjee on 30/4/21.
//
import ImageSlideshow
import UIKit
class ViewController: UIViewController {
// Create the ImageSlideShow Object
@IBOutlet weak var slideShow: ImageSlideshow!
override func viewDidLoad() {
super.viewDidLoad()
//Define the InputSource, with an array of images that you need to slideshow
slideShow.setImageInputs([
//The below asset names has to be updated to your image asset names
ImageSource(image: UIImage(named: "team1")!),
ImageSource(image: UIImage(named: "team2")!),
ImageSource(image: UIImage(named: "team3")!)
])
//Create the pageIndicator
let pageIndicator = UIPageControl()
pageIndicator.currentPageIndicatorTintColor = UIColor.lightGray
pageIndicator.pageIndicatorTintColor = UIColor.black
slideShow.pageIndicator = pageIndicator
//Label the pae indicator showing the page number e.g. 2/5
slideShow.pageIndicator = LabelPageIndicator()
//Enable the fullscreen view upon tapping the image
let gestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(ViewController.didTap))
slideShow.addGestureRecognizer(gestureRecognizer)
view.addSubview(slideShow)
}
//This is the selector method that is called upon tapping the image
@objc func didTap() {
slideShow.presentFullScreenController(from: self)
}
}