WWCircularCollectionView 0.0.3

WWCircularCollectionView 0.0.3

Maintained by William-Weng.



  • By
  • 翁禹斌(William.Weng)

WWCircularCollectionView

一個可以無限滾動的滾輪

Swift 4.0 Version Platform License

 一個自訂的CircularCollectionView (上傳至Cocoapods)

使用範例

IBOutlet

import UIKit
import WWCircularCollectionView

class ViewController: UIViewController {
    
    @IBOutlet weak var nowLabel: UILabel!
    @IBOutlet weak var lastLabel: UILabel!
    @IBOutlet weak var collectionView: WWCircularCollectionView!
    
    let isInfinity = true
    
    override func viewDidLoad() {
        super.viewDidLoad()
        delegateSetting()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}

extension ViewController {
    
    func delegateSetting() {
        
        guard let layout = collectionView.collectionViewLayout as? WWCircularCollectionViewLayout else { return }
        
        layout.wwDelegate = self
        collectionView.wwDelegate = self
    }
}

extension ViewController: WWCircularCollectionViewDelegate {
    
    func isInfinity(_ wwCircularCollectionView: WWCircularCollectionView) -> Bool {
        return isInfinity
    }
    
    func imagesDiectory(_ wwCircularCollectionView: WWCircularCollectionView) -> [String] {
        return Bundle.main.paths(forResourcesOfType: "png", inDirectory: "Images")
    }
}

extension ViewController: WWCircularCollectionViewLayoutDelegate {
    
    func wwCircularCollectionViewLayout(_ wwCircularCollectionViewLayout: WWCircularCollectionViewLayout, selectedIndex index: Int) {
        nowLabel.text = index.description
    }
    
    func wwCircularCollectionViewLayout(_ wwCircularCollectionViewLayout: WWCircularCollectionViewLayout, lastSelectedIndex index: Int) {
        lastLabel.text = index.description
    }
}