FCCarouselView 1.0.7

FCCarouselView 1.0.7

测试已测试
语言语言 SwiftSwift
许可 MIT 许可证
发布上次发布2017 年 3 月
SwiftSwift 版本3.1
SPM支持 SPM

ljlin1520 维护。



  • 作者:
  • liujianlin

Build Status
Swift 实现的循环轮播
1. 简单易用,支持 CocoaPodsCarthage
2. 自带缓存,缓存参考猫神的 Kingfisher;
3. 支持 GIF 动图,无第三方依赖
4. 也可以自己注册 Cell,更灵活地展示自定义 View

先不聊了,上图

demo

要求

  • iOS 8+
  • Swift 3.0.1
  • Xcode 8.2.1

安装

3. 将代码拖到您的项目中

使用

//step 1
import FCCarouselView

//step 2
//MARK: getter 懒加载
fileprivate lazy var carouselView:CarouselView = {
    let carouselView = CarouselView(frame: CGRect(x: 0, y: 64, width: UIScreen.main.bounds.width, height: 200))
    carouselView.delegate = self
    //1
    var carouselData = CarouselData()
    carouselData.image = UIImage(named: "1")
    carouselData.detail = "I created a swift class with string optionals (String?) and instantiated the class in a different swift file and got a compile error."
    carouselView.dataSource.append(carouselData)
    //2
    carouselData = CarouselData()
    carouselData.imageURL = URL(string: "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcSMFynE3clrgzCU2ZDw9SDn5gM2JuwEsCE37Qf4S6uBlJljejEYWg")
    carouselData.detail = "When I instantiate the class"
    carouselView.dataSource.append(carouselData)
    //3
    carouselData = CarouselData()
    carouselData.image = UIImage(named: "3")
    carouselView.dataSource.append(carouselData)
    //4
    carouselData = CarouselData()
    carouselData.imageURL = URL(string: "https://g.twimg.com/blog/blog/image/Cat-party.gif")
    carouselData.detail = "If the var item = ShoppingListItem() is done in the appDelegate.swift, from the function application:didFinishLaunchingWithOptions we get the error"
    carouselView.dataSource.append(carouselData)
    //5
    carouselData = CarouselData()
    carouselData.imageURL = URL(string: "https://www.baidu.com/123")
    carouselData.detail = "<class> cannot be initialised because it has no accessible initializers"
    carouselView.dataSource.append(carouselData)
    return carouselView
}()

//step 3
override func viewDidLoad() {
    view.addSubview(carouselView)
}

自动滚动选项

public enum AutoScrollOption {
    case enable(Bool) //是否开启自动轮播,默认开启
    case timeInterval(Foundation.TimeInterval)  //轮播频率
}

//such as
sbCarouselView.autoScrollOptions = [.enable(false)]

分页控制选项

public enum PageControlOption {
    case hidden(Bool)
    case indicatorTintColor(UIColor)
    case currentIndicatorTintColor(UIColor)
}
//such as
sbCarouselView.pageControlOptions = [.indicatorTintColor(UIColor.greenColor())
            , .currentIndicatorTintColor(UIColor.grayColor())]        

CarouselView 代理

@objc public protocol CarouselViewDelegate: class {
    //自定义Cell时才使用到
    @objc optional func carouselView(_ view:CarouselView, cellAtIndexPath indexPath:IndexPath, pageIndex: Int) -> UICollectionViewCell
    //点击事件
    @objc optional func carouselView(_ view:CarouselView, didSelectItemAtIndex index:NSInteger)
}

类似于 UICollectionDelegate 的自定义 Cell

//step 1 registerClass
carouselView.registerClass(CustomCollectionViewCell.self, forCellWithReuseIdentifier: NSStringFromClass(CustomCollectionViewCell.self))

//step 2 
func carouselView(_ view: CarouselView, cellAtIndexPath indexPath: IndexPath, pageIndex: Int) -> UICollectionViewCell {
    let customCell = carouselView.dequeueReusableCellWithReuseIdentifier(NSStringFromClass(CustomCollectionViewCell.self), forIndex: pageIndex) as! CustomCollectionViewCell
    if let detail = carouselView.dataSource[pageIndex] as? String {
        customCell.detailLabel.text = detail
    }
    return customCell
}

更多信息请查看 Demo

联系方式

有任何问题可以提出 issues 或联系我
微博 : @飛呈jerry
博客: https://www.fcgeek.com

许可证

FCCarouselView 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。