YLCycleScrollView 1.2.4

YLCycleScrollView 1.2.4

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

ZJModel维护。



  • Hearsayer

YLCycleScrollView

image

YLCycleScrollView是一个令人愉快的iOS滚动视图库,它基于UIScrollView,使用三个UIImageView来实现滚动循环效果,无论图片有多少。

YLCycleScrollView是一个基于UIScrollView的iOS平台下轻量级的滚动视图,无论多少张图片,都是用3个UIImageView来完成。

Podfile

使用CocoaPods将YLCycleScrollView集成到您的Xcode项目中,在Podfile中指定它

platform :ios, '8.0'
use_frameworks!
target 'TargetName' do
pod 'YLCycleScrollView'
end

然后,运行以下命令

$ pod install

如何使用

将以下代码添加到所需位置

// 懒加载 
lazy var cycleView: YLCycleScrollView = YLCycleScrollView(frame: CGRect(x: 0, y: 20, width: UIScreen.main.bounds.width, height: 200))

//图片集合
var images = ["http://bizhi.zhuoku.com/bizhi2008/0516/3d/3d_desktop_13.jpg",
              "http://tupian.enterdesk.com/2012/1015/zyz/03/5.jpg",
              "http://img.web07.cn/UpImg/Desk/201301/12/desk230393121053551.jpg",
              "http://wallpaper.160.com/Wallpaper/Image/1280_960/1280_960_37227.jpg",
              "http://bizhi.zhuoku.com/wall/jie/20061124/cartoon2/cartoon014.jpg"]

override func viewDidLoad() {
    super.viewDidLoad()

    var datas = [CycleModel]()

    // 根据URL生成数据模型
    for m in images {
        datas.append(CycleModel(urlString: m))
    }

    // 设置数据源,数据源是'CycleModel'对象,相当于数据模型,实际开发中,建议继承'CycleModel'来设置数据
    cycleView.dataSource = datas
        
    // 设置分页控件位置
    cycleView.indicatiorPosition = .left

    // 是否显示底部阴影条
    cycleView.isShowDimBar = true

    // 占位图片
    cycleView.placeholderImage = UIImage(named: "3")

    // 代理监听图片点击
    cycleView.delegate = self
    view.addSubview(cycleView)
}

建议您创建一个继承自以下类(YLCycleModel)的类作为数据源。

open class YLCycleModel: NSObject {

    /// URL字符串
    public var urlString: String 

    /// 文字
    public var text: String?

    public init(urlString: String, texts: String? = nil) {

        self.urlString = urlString

        self.text = texts

        super.init()
    }
}