Giter Site home page Giter Site logo

ywcycleviewdemo's Introduction

####前言 公司新项目采用Swift3.0开发,以前自己用的是OC 封装的,现在用不了,从github上拉下来的好像不行,都是以前老版本的,还要自己做版本提升,索性自己封装一个轮播,很多的轮播实现都是基于ScrollView水平添加多个ImageView实现,个人觉的不是很好,因为如果要播放的轮播图太多的话,这种方法会导致一次性创建多个ImageView,占用内存,所以推荐CollectionView。效果图如下: TextKitDemo1.gif

####使用说明 一切都在代码中,创建控件

    lazy var tableView = UITableView()
    lazy var modelMArr = [YWCycleModel]()
    var cycleView : YWCycleView?
    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.frame = view.bounds
        tableView.delegate = self
        tableView.dataSource = self
        view.addSubview(tableView)
        tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
        
        cycleView = YWCycleView(frame: CGRect(x: 0, y: 0, width: view.bounds.width, height: 250))
        guard let cycleView = cycleView else {
            return
        }
        cycleView.delegate = self
        tableView.tableHeaderView = cycleView
        requestData()
    }
    

模拟请求数据:

    func requestData() {
        let tempArr = [["title":"**奥运军团三金回顾","imageUrl":"http://pic33.nipic.com/20130916/3420027_192919547000_2.jpg"],
                       ["title":"《封神传奇》进世界电影特效榜单?山寨的!","imageUrl":"http://imgstore.cdn.sogou.com/app/a/100540002/503008.png"],
                       ["title":"奥运男子4x100自由泳接力 菲尔普斯","imageUrl":"http://i1.hexunimg.cn/2014-08-15/167580248.jpg"],
                       ["title":"顶住丢金压力 孙杨晋级200自决赛","imageUrl":"http://pic6.huitu.com/res/20130116/84481_20130116142820494200_1.jpg"]];
        for dic in tempArr {
            let model = YWCycleModel()
            model.imageStr = dic["imageUrl"]
            model.title = dic["title"]
            modelMArr.append(model)
        }
        guard let cycleView = cycleView else {
            return
        }
        cycleView.dataArr = modelMArr
    }

点击事件代理回调:

extension ViewController: YWCycleViewDelegate {
    func cycleViewDidSelected(cycleView: YWCycleView, selectedIndex: NSInteger) {
        print("打印了\(selectedIndex)")
    }
} 

这样一个轮播模块就完成了

####结语 只是展示如何使用的代码,有兴趣的同学欢迎去我的github下载相对应的代码Demo,如果觉得还行,可以放在以后项目中使用。如果代码哪里有问题,欢迎指教~~~~ ps:因为时间关系,很多属性来不及封装,我会在有时间的时候,多封装几种样式的。

####用到的三方

  • SDWebImage (近期换掉)

ywcycleviewdemo's People

Contributors

vvkeep avatar

Stargazers

MohsinAli avatar

Watchers

James Cloos avatar MohsinAli avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.