Skip to content

yasirdx777/DXImageSliderView

Repository files navigation

DXImageSliderView

Version License Platform

Features

  • Easy to use
  • Light weight
  • Customizable Page controller
  • Touch to pause auto scrolling

alt text

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

DXImageSliderView is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'DXImageSliderView'

Usage

First import DXImageSliderView

import DXImageSliderView

Then create the DXImageSliderView

    let imageSliderData = ["www.example.com/image1.jpg", "www.example.com/image2.jpg", "www.example.com/image3.jpg"]
    
    let imageSliderViewRatioToTheScreen:CGFloat = 2
    
    lazy var imageSliderView: DXImageSliderView = {
        let imageSliderView = DXImageSliderView(frame: CGRect.init(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.width / imageSliderViewRatioToTheScreen))
        imageSliderView.scrollDirection = .horizontal
        imageSliderView.delegate = self
        imageSliderView.reloadItemsCount(imageSliderData.count)
        imageSliderView.itemZoomScale = 1
        imageSliderView.itemSpacing = 0
        imageSliderView.initialIndex = 1
        imageSliderView.timeInterval = 3
        imageSliderView.isAutomatic = true
        imageSliderView.isInfinite = true
        imageSliderView.itemSize = CGSize(width: self.view.frame.width, height: self.view.frame.width /  imageSliderViewRatioToTheScreen)
        imageSliderView.center = self.view.center
        return imageSliderView
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.view.addSubview(imageSliderView)
    }

And implement DXImageSliderView delegates

    func imageSliderViewRegisterCellClasses() -> [String: AnyClass] {
        return ["CustomCollectionViewCell": CustomCollectionViewCell.self]
    }
    
    func imageSliderViewConfigureCell(collectionView: UICollectionView, cellForItemAt indexPath: IndexPath, realIndex: Int) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CustomCollectionViewCell", for: indexPath) as! CustomCollectionViewCell
        let item = imageSliderData[realIndex]
        cell.imageView.kf.setImage(with: URL(string: item)!, options: [
            .scaleFactor(UIScreen.main.scale),
            .transition(.fade(1)),
            .cacheOriginalImage,
        ])
        return cell
    }
    
    func imageSliderViewConfigurePageControl(_ imageSliderView: DXImageSliderView, pageControl: DXPageControl) {
        pageControl.isHidden = false
        pageControl.currentPageIndicatorTintColor =  .orange
        pageControl.pageIndicatorTintColor = .lightGray
        pageControl.frame = CGRect(x: 0, y: imageSliderView.bounds.height-25, width: imageSliderView.bounds.width, height: 25)
    }
    
    func imageSliderViewDidSelectedIndex(_ imageSliderView: DXImageSliderView, index: Int){
        print("item selected")
    }

Author

Yasir Romaya, yasir.romaya@gmail.com

License

DXImageSliderView is available under the MIT license. See the LICENSE file for more info.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published