Xcode 在图像显示滑块上显示api中的图像
我下载了这个库,我的目标是以Json的形式从web服务获取图像链接,然后显示它们 下面是如何通过互联网上的随机链接来实现这一点Xcode 在图像显示滑块上显示api中的图像,xcode,swift3,alamofire,slideshow,Xcode,Swift3,Alamofire,Slideshow,我下载了这个库,我的目标是以Json的形式从web服务获取图像链接,然后显示它们 下面是如何通过互联网上的随机链接来实现这一点 let alamofireSource = [AlamofireSource(urlString: "https://images.unsplash.com/photo-1432679963831-2dab49187847?w=1080")!, AlamofireSource(urlString: "https://images.unsplash.com/phot
let alamofireSource = [AlamofireSource(urlString:
"https://images.unsplash.com/photo-1432679963831-2dab49187847?w=1080")!,
AlamofireSource(urlString: "https://images.unsplash.com/photo-1447746249824-
4be4e1b76d66?w=1080")!,
AlamofireSource(urlString:
"https://images.unsplash.com/photo-1463595373836-6e0b0a8ee322?w=1080")!]
我想我应该做的是:
1-对我的api执行调用请求
2-将图像URL保存在数组中
3-循环遍历数组,并在[AlamofResource(urlString:
“数组中的变量”)!
这是正确的方法还是没有使用这个库还有更好的方法
更新
var Pics = [JSON]()
open override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .portrait
}
@IBOutlet var slideshow: ImageSlideshow!
override func viewWillAppear(_ animated: Bool) {
let url = "http://localhost:8000/api/hello"
Alamofire.request(url).responseJSON { response in
if let value: AnyObject = response.result.value as AnyObject? {
//Handle the results as JSON
let json = JSON(value)
for (key, subJson) in json["pic"] {
self.Pics.append(subJson) as? String
}
print(self.Pics)
}
}
}
let kingfisherSource = [KingfisherSource(urlString: Pics)!] // error
override func viewDidLoad() {
super.viewDidLoad()
slideshow.backgroundColor = UIColor.white
slideshow.slideshowInterval = 5.0
slideshow.pageControlPosition = PageControlPosition.underScrollView
slideshow.pageControl.currentPageIndicatorTintColor = UIColor.lightGray
slideshow.pageControl.pageIndicatorTintColor = UIColor.black
slideshow.contentScaleMode = UIViewContentMode.scaleAspectFill
slideshow.currentPageChanged = { page in
print("current page:", page)
}
注:
这是json数据的格式
[
"http://localhost:8000/images/1490104055.jpg",
"http://localhost:8000/images/1490104055.jpg",
"http://localhost:8000/images/1490104055.jpg",
"http://localhost:8000/images/1490104055.jpg",
"http://localhost:8000/images/1490104055.jpg",
null,
null
]
谢谢