Skip to content

借鉴前辈写的OC代码,实现swift版图片轮播功能,前辈的思想确实不错

Notifications You must be signed in to change notification settings

zhanghongdou/CycleScrollView-swift

Repository files navigation

CycleScrollView-Swift

什么是 CycleScrollView-Swift

这是一个基于swift语言实现图片轮播的封装

效果图展示

效果图1

效果图2

使用方法

//实例化进行添加在指定的View上面
let cycleView = CycleScrollView.init(frame: CGRectMake(0, 64, CGRectGetWidth(self.view.frame), 200), animationDuration: 3.0)
cycleView.backgroundColor = UIColor.orangeColor()
self.view.addSubview(cycleView)

//设置轮播图的数组URL
let dataArray = ["http://img04.sogoucdn.com/app/a/100520020/50c11a6a4b7a4da664e93a9cf4c061ce",
"http://img04.sogoucdn.com/app/a/100520024/1f9163519dac6b2138c7d96b5598467e",
"http://img01.sogoucdn.com/app/a/100520024/e2f057ede9d3cafabed15418bad2ee17",
"http://img01.sogoucdn.com/app/a/100520020/2001859ba6fca0a525728c7568782d89",
"http://img04.sogoucdn.com/app/a/100520024/f4d580ab0d9f5d514c9471b23bba0561",
"http://img03.sogoucdn.com/app/a/100520024/30e8009fb8710f519b565b1cd17df7ec",
"http://img02.sogoucdn.com/app/a/100520020/992e6ea334d3d1c34abfa5ea1ec0978a"]
//创建加载图片的ImageView
for index in 0..<dataArray.count {
let imageView = UIImageView.init(frame: CGRectMake(0, 0, CGRectGetWidth(self.view.frame), 200))
imageView.sd_setImageWithURL(NSURL(string: dataArray[index]))
self.imageViewArray.addObject(imageView)
}

    //闭包返回相应的View</br> 
    cycleView.fetchContentViewAtIndex = {(pageIndex: NSInteger) in</br> 
        return (self.imageViewArray[pageIndex] as! UIView)</br> 
    }</br> 
      
    
    //这个是吧所有的URL传过去,这一步必须做</br> 
    cycleView.imageURLArray = dataArray</br> 
    //传入相应的count</br> 
    cycleView.totalPageCount = self.imageViewArray.count</br> 
    //设置pageContol的count</br> 
    cycleView.pageControl?.numberOfPages = self.imageViewArray.count</br> 
    //点击的闭包</br> 
    cycleView.tapActionBlock = { (pageIndex: NSInteger) in</br> 
        print(pageIndex)</br> 
    }</br> 
   </p>

About

借鉴前辈写的OC代码,实现swift版图片轮播功能,前辈的思想确实不错

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published