1.cocopods中集成第三方
pod 'SQAutoScrollView'
//图片若是个网络数据则用Alamofire进行请求
pod 'Alamofire'
2.先进行解析图片数据
//MARK:解析数据,添加轮播图
fileprivate func loadCycleView() {
//Alamofire解析数据
let parameters = ["method":"app.resource.getimg","position":"News-Banner"]
Alamofire.request("http://test.bit.api.meeboo.cc", method: .get, parameters: parameters, encoding: URLEncoding.default, headers: nil).responseJSON { (response) in
if(response.error == nil){
print(response.result.value)
}else{
print("请求失败\(String(describing: response.error))")
}
}
//解析出的图片网址字符串
let urls = ["http://www.zhanglirong.cn/themes/simplebootx_en-us/Public/assets/images/demo/1.jpg",
"http://www.zhanglirong.cn/themes/simplebootx_en-us/Public/assets/images/demo/3.jpg",
"http://www.zhanglirong.cn/themes/simplebootx_en-us/Public/assets/images/demo/2.jpg",
]
}
3.将图片添加都轮播图展示出来
let cycleView = SQAutoScrollView(frame: CGRect.init(x: 0, y: 105, width: view.bounds.size.width, height: 150), urls: urls, didItemCallBack: { (view, index) in
print("view--->\(view), index-->\(index)")
})
view.addSubview(cycleView)
4.在viewDidLoad中实现方法