[CocoaPods] How to Auto Slide Page Use FSPagerView


This time i will give an example for Auto Slide Page, and will use FSPagerView for slider and
Kingfisher as image

here's an example code:

1.   input UiView then select to costum class FSPagerView ,  and than


- will then look like this






2. Full Code

import UIKit
import Kingfisher
import FSPagerView

class AutoSlideViewController: UIViewController, FSPagerViewDataSource, FSPagerViewDelegate {
   
    @IBOutlet weak var viewBanner: FSPagerView! {
        didSet {
            self.viewBanner.register(FSPagerViewCell.self, forCellWithReuseIdentifier: "cell")
            self.viewBanner.transformer = FSPagerViewTransformer(type: .linear)
            self.viewBanner.itemSize = CGSize(width: 300, height: 150)
            self.viewBanner.isInfinite = true
            self.viewBanner.contentMode = .scaleAspectFit
            self.viewBanner.backgroundColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
            self.viewBanner.automaticSlidingInterval = 3.0
        }
    }
    @IBOutlet weak var pageC: UIPageControl!
    

    var arrayImageFisher = ["data1.jpg, data2.jpg, data3.jpg"]
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.pageC.hidesForSinglePage = true
    
    }
    
  
    
    func numberOfItems(in pagerView: FSPagerView) -> Int {
        self.pageC.numberOfPages = self.arrayImageFisher.count
        return self.arrayImageFisher.count
    }
    
    func pagerView(_ pagerView: FSPagerView, cellForItemAt index: Int) -> FSPagerViewCell {
        let cell = pagerView.dequeueReusableCell(withReuseIdentifier: "cell", at: index)
        
        let resource = ImageResource(downloadURL: URL(string: arrayImageFisher[index])!)
        
        cell.imageView?.kf.setImage(with: resource)
        cell.imageView?.contentMode = .scaleAspectFill
        cell.imageView?.clipsToBounds = true
        self.pageC.currentPage = index
        return cell
    }
    
    
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        let page = scrollView.contentOffset.x / scrollView.frame.width
        pageC.currentPage = Int(page)
        
    }
    

}




2 comments:

  1. Hi, do you know how to remove the default page control? Thanks.

    ReplyDelete
  2. I really like your take on the issue. I now have a clear idea on what this matter is all about.. slide boards expert

    ReplyDelete